C language Multiple Choice Questions


C language Multiple Choice Questions

1) What is the 16-bit compiler allowable range for integer constants?
-3.4e38 to 3.4e38
-32767 to 32768
-32668 to 32667
-32768 to 32767 



Answer: (d) -32768 to 32767

Explanation: In a 16-bit C compiler, we have 2 bytes to store the value.
The range for signed integers is -32768 to 32767.
The range for unsigned integers is 0 to 65535.
The range for unsigned character is 0 to 255.

2) Study the following program:

main()
{printf("javatpoint");
main();} main() {printf("javatpoint"); main();}

What will be the output of this program?
Wrong statement
It will keep on printing javatpoint
It will Print javatpoint once
None of the these 



Answer: (b) It will keep on printing javatpoint

Explanation: In this program, the main function will call itself again and again. Therefore, it will continue to print javatpoint.

3) What is required in each C program?
The program must have at least one function.
The program does not require any function.
Input data
Output data 



Answer: (a) The program must have at least one function.

Explanation: Any C program has at least one function, and even the most trivial programs can specify additional functions. A function is a piece of code. In other words, it works like a sub-program.

4) What will this program print?

main()
{
int i = 2;
{
int i = 4, j = 5;
printf("%d %d", i, j);
}
printf("%d %d", i, j);
} main() { int i = 2; { int i = 4, j = 5; printf("%d %d", i, j); } printf("%d %d", i, j); }
4525
2525
4545
None of the these 



Answer: (a) 4525

Explanation: In this program, it will first print the inner value of the function and then print the outer value of the function.

5) Which of the following comment is correct when a macro definition includes arguments?
The opening parenthesis should immediately follow the macro name.
There should be at least one blank between the macro name and the opening parenthesis.
There should be only one blank between the macro name and the opening parenthesis.
All the above comments are correct. 



Answer: (a) The opening parenthesis should immediately follow the macro name.

Explanation: None

6) What is a lint?
C compiler
Interactive debugger
Analyzing tool
C interpreter 



Answer: (c) Analyzing tool

Explanation: Lint is an analyzing tool that analyzes the source code by suspicious constructions, stylistic errors, bugs, and flag programming errors. Lint is a compiler-like tool in which it parses the source files of C programming. It checks the syntactic accuracy of these files.

7) What is the output of this statement "printf("%d", (a++))"?
The value of (a + 1)
The current value of a
Error message
Garbage 



Answer: (b) The current value of "a".

Explanation: None

8) Study the following program:

main()
{
char x [10], *ptr = x;
scanf ("%s", x);
change(&x[4]);
}
change(char a[])
{
puts(a);
} main() { char x [10], *ptr = x; scanf ("%s", x); change(&x[4]); } change(char a[]) { puts(a); }

If abcdefg is the input, the output will be
abcd
abc
efg
Garbage 



Answer: (c) efg

Explanation: None

9) Study the following program:

main()
{
int a = 1, b = 2, c = 3:
printf("%d", a + = (a + = 3, 5, a))
} main() { int a = 1, b = 2, c = 3: printf("%d", a + = (a + = 3, 5, a)) }

What will be the output of this program?
6
9
12



Answer: (d) 8

Explanation: It is an effect of the comma operator.

a + = (a + = 3, 5, a)

It first evaluates to "a + = 3" i.e. a = a + 3 then evaluate 5 and then evaluate "a".

Therefore, we will get the output is 4.

Then,

a + = 4

It gives 8 as the output.

10) What does this declaration mean?

int x : 4; int x : 4;
X is a four-digit integer.
X cannot be greater than a four-digit integer.
X is a four-bit integer.
None of the these 



Answer: (c) X is a four-bit integer.

Explanation: This means, "X" is a four bit integer.

11) Why is a macro used in place of a function?
It reduces execution time.
It reduces code size.
It increases execution time.
It increases code size. 



Answer: (d) It reduces code size.

Explanation: Macro is used in place of a function because it reduces code size, and very efficient.

12) In the C language, the constant is defined _______.
Before main
After main
Anywhere, but starting on a new line.
None of the these. 



Answer: (c) Anywhere, but starting on a new line.

Explanation: In the C language, the constant is defined anywhere, but starting on a new line.

13) How many times will the following loop execute?

for(j = 1; j <= 10; j = j-1) for(j = 1; j <= 10; j = j-1)
Forever
Never
0



Answer: (a) Forever

Explanation: None

14) A pointer is a memory address. Suppose the pointer variable has p address 1000, and that p is declared to have type int*, and an int is 4 bytes long. What address is represented by expression p + 2?
1002
1004
1006
1008 



Answer: (d) 1008

Explanation: None

15) What is the result after execution of the following code if a is 10, b is 5, and c is 10?

If ((a > b) && (a <= c))
a = a + 1;
else
c = c+1; If ((a > b) && (a <= c)) a = a + 1; else c = c+1;
a = 10, c = 10
a = 11, c = 10
a = 10, c = 11
a = 11, c = 11 



Answer: (b) a = 11, c = 10

Explanation: None

16) Which one of the following is a loop construct that will always be executed once?
for
while
switch
do while 



Answer: (d) do while

Explanation: The body of a loop is often executed at least once during the do-while loop. Once the body is performed, the condition is tested. If the condition is valid, it will execute the body of a loop; otherwise, control is transferred out of the loop.

17) Which of the following best describes the ordering of destructor calls for stack-resident objects in a routine?
The first object created is the first object destroyed; last created is last destroyed.
The first object destroyed is the last object destroyed; last created is first destroyed.
Objects are destroyed in the order they appear in memory, the object with the lowest memory address is destroyed first.
The order is undefined and may vary from compiler to compiler. 



Answer: (b) The first object destroyed is the last object destroyed; last created is first destroyed.

Explanation: None

18) How many characters can a string hold when declared as follows?

char name[20]: char name[20]:
18
19
20
None of the these 



Answer: (b) 20

Explanation: None

19) Directives are translated by the
Pre-processor
Compiler
Linker
Editor 



Answer: (a) Pre-processor

Explanation: In C language, the pre-processor is a macro processor that is dynamically used by the C programmer to modify the program before it is properly compiled (Before construction, pro-processor directives are implemented).

20) How many bytes does "int = D" use?
0
1
2 or 4
10 



Answer: (c) 2 or 4

Explanation: The int type takes 2 or 4 bytes.

21) What feature makes C++ so powerful?
Easy implementation
Reusing the old code
Easy memory management
All of the above 



Answer: (d) All of the above

Explanation: None

22) Which of the following will copy the null-terminated string that is in array src into array dest?
dest = src;
dest == src;
strcpy(dest, src);
strcpy(src, dest); 



Answer: (c) strcpy(dest, src)

Explanation: strcpy is a string function that is used to copy the string between the two files. strcpy(destination, source)

23) In the statement "COUT << "javatpoint" << end1;", end1 is a ___.
Extractor
Inserter
Manipulator
Terminator 



Answer: (c) Manipulator

Explanation: End1 is an I/O manipulator that takes effect in printing a new line '\ n' character and then flushing the output stream.

24) Each instance of a class has a different set of
Class interfaces
Methods
Return types
Attribute values 



Answer: (d) Attribute values

Explanation: Each instance of the class has a different set of attribute values

25) How many instances of a class can be declared?
1
10
As per required
None of the these 



Answer: (c) As per required

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; int num = 58; 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 



Answer: (b) 39

Explanation: None

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

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



Answer: (c) 13

Explanation: None

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

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



Answer: (c) 13

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);
} #include <stdio.h> 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 



Answer: (d) 11, 11

Explanation: None

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

int * aPtr;
*aPtr = 100;
cout << *aPtr + 2; int * aPtr; *aPtr = 100; cout << *aPtr + 2;
100
102
104
108 



Answer: (b) 102

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; char str[80]; char * p; p = str;
p + 4
*p + 4
*(p + 4)
p [3] 



Answer: (c) *(p + 4)

Explanation: None

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

int ** balance; 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 



Answer: (b) Balance is a pointer to a pointer to an 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: 



Answer: (c) d = b;

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. 



Answer: (b) A pointer must point to a data item on the heap (free store).

Explanation: None

36) Which of the following SLT template class is a container adaptor class?
Stack
List
Deque
Vector 



Answer: (a) Stack

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

37) What kinds of iterators can be used with vectors?
Forward iterator
Bi-directional iterator
Random access iterator
All of the above 



Answer: (d) 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 



Answer: (c) 2004

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 + p2;
p1 = p1 - 9;
p2 = p2 + 9;
cout << p1 - p2; 



Answer: (a) p1 = p1 + p2;

Explanation: None

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; cPtr = cPtr + 5;
305
310
320
340 



Answer: (a) 305

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; 



Answer: (b) int my_num = 100000;

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 



Answer: (d) 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;
} 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; }
a = 20, b = 20
a = 10, b = 20
a = 20, b = 10
a = 10, b = 10 



Answer: (c) a = 20, 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 



Answer: (e) All of the these

Explanation: All statements are true

45) What does this statement mean?

x - = y + 1; x - = y + 1;
x = x - y + 1
x = -x - y - 1
x = x + y - 1
x = x - y - 1 



Answer: (d) 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;
} for (i = 3; i < 15; i + = 3) {printf ("%d", i); ++i; }

What will be the output?
3 6 9 12
3 6 9 12 15
3 7 11
3 7 11 15 



Answer: (c) 3 7 15

Explanation: None

47) Study the following statement

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

What will be the output?
Hello, World!
Hello,
World!
Hello
Compile error 



Answer: (b) Hello, World!

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}; 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 



Answer: (a) num[9] is the last element of the array num

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");
} main() { printf ("\\n ab"); printf ("\\b si"); printf ("\\r ha"); }
absiha
asiha
haasi
hai 



Answer: (d) 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);
} void main() { int i = 065, j = 65; printf ("%d %d", i, j); }
065 65
53 65
65 65
Syntax error 



Answer: (b) 53 65

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

Comments

Popular posts from this blog

Mini-Max Algorithm in Artificial Intelligence

Alpha-Beta Pruning

SQL Multiple Choice Questions