Objective type (MCQ) questions on C programming language Part 4

C programming language multiple type questions for exams point of view 

Basic C programming MCQ

25) How many instances of a class can be declared?

  1. 1
  2. 10
  3. As per required
  4. None of the these

Explanation: You can always declare multiple instances of a class, as per required. Each object will hold its own individual inner variables (unless they are static, in which case they are shared).


26) What will the result of num variable after execution of the following statements?

int num = 58;  
num % = 11;  
  1. 3
  2. 5
  3. 8
  4. 11

Answer: (a) 3

Explanation: num = 58

num % = 11

num = num % 11

num = 58 % 11

num = 3


27) What is the maximum number of characters that can be held in the string variable char address line [40]?

  1. 38
  2. 39
  3. 40
  4. 41

28) What will the result of num1 variable after execution of the following statements?

int j = 1, num1 = 4;  
while (++j <= 10)  
{  
  num1++;  
}  
  1. 11
  2. 12
  3. 13
  4. 14

29) What will the result of len variable after execution of the following statements?

int len;  
char str1[] = {"39 march road"};  
len = strlen(str1);  
  1. 11
  2. 12
  3. 13
  4. 14

Explanation: strlen is a string function that counts the word and also count the space in the string. (39 march road) = 13


30) Study the following statement

#include <stdio.h>  
    int main()  
    {  
        int *ptr, a = 10;  
        ptr = &a;  
        *ptr += 1;  
        printf("%d,%d/n", *ptr, a);  
    }  

What will be the output?

  1. 10, 10
  2. 10, 11
  3. 11, 10
  4. 11, 11

31) Given the following statement, what will be displayed on the screen?

int * aPtr;  
*aPtr = 100;  
cout << *aPtr + 2;  
  1. 100
  2. 102
  3. 104
  4. 108

Explanation: aPtr is an integer pointer which value is 100.

= *aPtr + 2

= 100 + 2

= 102


32) Give the following declarations and an assignment statement. Which one is equivalent to the expression str [4]?

char str[80];  
char * p;  
p = str;  
  1. p + 4
  2. *p + 4
  3. *(p + 4)
  4. p [3]

33) Which one is the correct description for the variable balance declared below?

  1. int ** balance;  
  1. Balance is a point to an integer.
  2. Balance is a pointer to a pointer to an integer.
  3. Balance is a pointer to a pointer to a pointer to an integer.
  4. Balance is an array of integer.

Explanation: This code description states that the remainder is a pointer to a pointer to an integer.


34) A class D is derived from a class B, b is an object of class B, d is an object of class D, and pb is a pointer to class B object. Which of the following assignment statement is not valid?

  1. d = d;
  2. b = d;
  3. d = b;
  4. *pb = d:

Explanation: A class D is derived from a class B, so "d" is not equal to b.


35) Which of the following statement is not true?

  1. A pointer to an int and a pointer to a double are of the same size.
  2. A pointer must point to a data item on the heap (free store).
  3. A pointer can be reassigned to point to another data item.
  4. A pointer can point to an array.

36) Which of the following SLT template class is a container adaptor class?

  1. Stack.
  2. List.
  3. Deque.
  4. Vector.

Explanation: Container Adaptors is the subset of Containers that provides many types of interface for sequential containers, such as stack and queue.


37) What kinds of iterators can be used with vectors?

  1. Forward iterator.
  2. Random access iterator.
  3. Bi-directional iterator.
  4. All of the above

Explanation: An iteration is like a pointer, indicating an element inside the container. All these types of iterations can be used with vectors.


38) Let p1 be an integer pointer with a current value of 2000. What is the content of p1 after the expression p1++ has been evaluated?

  1. 2001
  2. 2002
  3. 2004
  4. 2008

Explanation: The size of one pointer integer is 4 bytes. The current value of p1 is 2000.

p1++ = p1 + 1

p1++ = 2004


39) Let p1 and p2 be integer pointers. Which one is a syntactically wrong statement?

p1 = p1 - 9;

40) Suppose that cPtr is a character pointer, and its current content is 300. What will be the new value in cPtr after the following assignment?

cPtr = cPtr + 5;  
  1. 305
  2. 310
  3. 320
  4. 340

Explanation: cPtr = cPtr + 5

cPtr = 300 + 5

cPtr = 305


41) Which is valid expression in c language?

  1. int my_num = 100,000;
  2. int my_num = 100000;
  3. int my num = 1000;
  4. int my num == 10000;

Explanation: Special symbol, Space, and comma cannot be used in a variable name in c language.


42) If addition had higher precedence than multiplication, then the value of the expression (1 + 2 * 3 + 4 * 5) would be which of the following?

  1. 27
  2. 47
  3. 69
  4. 105

Explanation: (1 + 2 * 3 + 4 * 5)

= (1 + 2) * (3 + 4) * 5

= 3 * 7 * 5

= 105


43) What will be the output of this program?

int main()      
{      
int a=10, b=20;        
printf("a=%d b=%d",a,b);        
a=a+b;      
b=a-b;      
a=a-b;      
printf("a=%d b=%d",a,b);      
return 0;    
}     
  1. a = 20, b = 20
  2. a = 10, b = 20
  3. a = 20, b = 10
  4. a = 10, b = 10

Explanation: This program is a swapping program.

a = a + b → a = 10 + 20 → a = 30

b = a - b → b = 30 - 20 → B = 10

a = a - b → a = 30 - 10 → a = 20


44) The following statements are about EOF. Which of them is true?

  1. Its value is defined within stdio.h
  2. Its value is implementation-dependent
  3. Its value can be negative
  4. Its value should not equal the integer equivalent of any character
  5. All of the these

Explanation: All statements are true


45) What does this statement mean?

  1. x - = y + 1;  
  1. x = x - y + 1
  2. x = -x - y - 1
  3. x = x + y - 1
  4. x = x - y - 1

Explanation: x - = y + 1

x = x - (y + 1)

So, x = x - y - 1


46) Study the following statement

for (i = 3; i < 15; i + = 3)  
{
printf ("%d", i);  
 ++i;  
}  

What will be the output?

  1. 3 6 9 12
  2. 3 6 9 12 15
  3. 3 7 11
  4. 3 7 11 15

47) Study the following statement

main()  
{     
   char *s = "Hello,"  
   "World!";  
   printf("%s", s);  
}  

What will be the output?

  1. Hello, World!
  2. Hello,
    World!
  3. Hello
  4. Compile error

Explanation: The output of this program is "Hello, World!". This program's output will not appear in the new line because the \ n escape sequence has not been used in this program.


48) Study the following array definition

  1. int num[10] = {3, 3, 3};  

Which of the following statement is correct?

  1. num[9] is the last element of the array num.
  2. The value of num[8] is 3.
  3. The value of num[3] is 3.
  4. None of the above.

Explanation: The num[9] is the last element of the array number because the total element in this array is 10, and the array starts with 0, so the last element of the array is the num[9].


49) What will the output after execution of the following statements?

main()  
{  
  printf ("\\n ab");  
  printf ("\\b si");  
  printf ("\\r ha");  
}  
  1. absiha
  2. asiha
  3. haasi
  4. hai

Explanation:

  • \\n - newline - printf("\\nab"); - Prints 'ab'
  • \\b - backspace - printf("\\bsi"); - firstly '\\b' removes 'b' from 'ab ' and then prints 'si'. So, after execution of printf("\\bsi"); it is 'asi'
  • \\r - linefeed - printf("\\rha"); - Now here '\\r' moves the cursor to the start of the current line and then override 'asi' to 'hai'

50) What will the output after execution of the following statements?

void main()  
{  
  int i = 065, j = 65;  
  printf ("%d %d", i, j);  
}  
  1. 065 65.
  2. 53 65.
  3. 65 65.
  4. Syntax error.

Explanation: This value (065) is an octal value, and it equals to the decimal value 53.



1 Comments

Previous Post Next Post