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
- 10
- As per required
- 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?
num % = 11;
- 3
- 5
- 8
- 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]?
- 38
- 39
- 40
- 41
28) What will the result of num1 variable after execution of the following statements?
while (++j <= 10)
{
num1++;
}
- 11
- 12
- 13
- 14
29) What will the result of len variable after execution of the following statements?
- 11
- 12
- 13
- 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
int main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
printf("%d,%d/n", *ptr, a);
}
What will be the output?
- 10, 10
- 10, 11
- 11, 10
- 11, 11
31) Given the following statement, what will be displayed on the screen?
*aPtr = 100;
cout << *aPtr + 2;
- 100
- 102
- 104
- 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 * p;
p = str;
- p + 4
- *p + 4
- *(p + 4)
- p [3]
33) Which one is the correct description for the variable balance declared below?
- int ** balance;
- Balance is a point to an integer.
- Balance is a pointer to a pointer to an integer.
- Balance is a pointer to a pointer to a pointer to an integer.
- 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?
- d = d;
- b = d;
- d = b;
- *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?
- A pointer to an int and a pointer to a double are of the same size.
- A pointer must point to a data item on the heap (free store).
- A pointer can be reassigned to point to another data item.
- A pointer can point to an array.
36) Which of the following SLT template class is a container adaptor class?
- Stack.
- List.
- Deque.
- 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?
- Forward iterator.
- Random access iterator.
- Bi-directional iterator.
- 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?
- 2001
- 2002
- 2004
- 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?
- 305
- 310
- 320
- 340
Explanation: cPtr = cPtr + 5
cPtr = 300 + 5
cPtr = 305
41) Which is valid expression in c language?
- int my_num = 100,000;
- int my_num = 100000;
- int my num = 1000;
- 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?
- 27
- 47
- 69
- 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 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;
}
- a = 20, b = 20
- a = 10, b = 20
- a = 20, b = 10
- 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?
- Its value is defined within stdio.h
- Its value is implementation-dependent
- Its value can be negative
- Its value should not equal the integer equivalent of any character
- All of the these
Explanation: All statements are true
45) What does this statement mean?
- x - = y + 1;
- x = x - y + 1
- x = -x - y - 1
- x = x + y - 1
- x = x - y - 1
Explanation: x - = y + 1
x = x - (y + 1)
So, x = x - y - 1
46) Study the following statement
{
++i;
}
What will be the output?
- 3 6 9 12
- 3 6 9 12 15
- 3 7 11
- 3 7 11 15
47) Study the following statement
{
char *s = "Hello,"
"World!";
printf("%s", s);
}
What will be the output?
- Hello, World!
- Hello,World!
- Hello
- 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
- int num[10] = {3, 3, 3};
Which of the following statement is correct?
- num[9] is the last element of the array num.
- The value of num[8] is 3.
- The value of num[3] is 3.
- 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?
{
printf ("\\n ab");
printf ("\\b si");
printf ("\\r ha");
}
- absiha
- asiha
- haasi
- 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?
{
int i = 065, j = 65;
printf ("%d %d", i, j);
}
- 065 65.
- 53 65.
- 65 65.
- Syntax error.
Explanation: This value (065) is an octal value, and it equals to the decimal value 53.