Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
64 views27 pages

C Language MCQ

The document consists of multiple-choice questions (MCQs) related to the C programming language, covering topics such as data types, functions, pointers, and control structures. Each question is followed by the correct answer and an explanation. The document serves as a study guide for individuals preparing for C programming assessments or interviews.

Uploaded by

zeeshan.ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views27 pages

C Language MCQ

The document consists of multiple-choice questions (MCQs) related to the C programming language, covering topics such as data types, functions, pointers, and control structures. Each question is followed by the correct answer and an explanation. The document serves as a study guide for individuals preparing for C programming assessments or interviews.

Uploaded by

zeeshan.ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

C language MCQ

1) What is the 16-bit compiler allowable range for integer constants?

a. -3.4e38 to 3.4e38

b. -32767 to 32768

c. -32668 to 32667

d. -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 characters is 0 to 255.

2) Study the following program:

1. main()
2. {printf("javatpoint");
3. main();}

What will be the output of this program?

a. Wrong statement

b. It will keep on printing javatpoint

c. It will Print javatpoint once

d. 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?

a. The program must have at least one function.

b. The program does not require any function.

c. Input data

d. 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?

1. main()
2. {
3. int i = 2;
4. {
5. int i = 4, j = 5;
6. printf("%d %d", i, j);
7. }
8. printf("%d %d", i, j);
9. }

a. 4525
b. 2525

c. 4545

d. 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?

a. The opening parenthesis should immediately follow the macro name.

b. There should be at least one blank between the macro name and the opening
parenthesis.

c. There should be only one blank between the macro name and the opening
parenthesis.

d. All the above comments are correct.

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

Explanation: None

6) What is a lint?

a. C compiler

b. Interactive debugger

c. Analyzing tool

d. 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++))"?

a. The value of (a + 1)

b. The current value of a

c. Error message

d. Garbage

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

Explanation: None

8) Study the following program:

1. main()
2. {
3. char x [10], *ptr = x;
4. scanf ("%s", x);
5. change(&x[4]);
6. }
7. change(char a[])
8. {
9. puts(a);
10. }
If abcdefg is the input, the output will be

a. abcd

b. abc

c. efg

d. Garbage

Answer: (c) efg

Explanation: None

9) Study the following program:

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

What will be the output of this program?

a. 6

b. 9

c. 12

d. 8

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?

1. int x : 4;

a. X is a four-digit integer.

b. X cannot be greater than a four-digit integer.

c. X is a four-bit integer.

d. 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?

a. It reduces execution time.

b. It reduces code size.

c. It increases execution time.

d. 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 _______.

a. Before main

b. After main

c. Anywhere, but starting on a new line.

d. 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?

1. for(j = 1; j <= 10; j = j-1)

a. Forever

b. Never

c. 0

d. 1

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?

AD

a. 1002

b. 1004

c. 1006

d. 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?

1. If ((a > b) && (a <= c))


2. a = a + 1;
3. else
4. c = c+1;

a. a = 10, c = 10

b. a = 11, c = 10

c. a = 10, c = 11

d. 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?
a. for

b. while

c. switch

d. 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?

a. The first object created is the first object destroyed; last created is last
destroyed.

b. The first object destroyed is the last object destroyed; last created is first
destroyed.

c. Objects are destroyed in the order they appear in memory, the object with the
lowest memory address is destroyed first.

d. 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?

1. char name[20]:
a. 18

b. 19

c. 20

d. None of the these

Answer: (b) 20

Explanation: None

19) Directives are translated by the

AD

a. Pre-processor

b. Compiler

c. Linker

d. 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?

a. 0

b. 1

c. 2 or 4

d. 10
Answer: (c) 2 or 4

Explanation: The int type takes 2 or 4 bytes.

21) What feature makes C++ so powerful?

a. Easy implementation

b. Reusing the old code

c. Easy memory management

d. 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?

a. dest = src;

b. dest == src;

c. strcpy(dest, src);

d. 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 ___.
a. Extractor

b. Inserter

c. Manipulator

d. 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

a. Class interfaces

b. Methods

c. Return types

d. 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?

a. 1

b. 10

c. As per required

d. 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?

1. int num = 58;


2. num % = 11;

a. 3

b. 5

c. 8

d. 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]?

a. 38

b. 39

c. 40
d. 41

Answer: (b) 39

Explanation: None

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

1. int j = 1, num1 = 4;
2. while (++j <= 10)
3. {
4. num1++;
5. }

a. 11

b. 12

c. 13

d. 14

Answer: (c) 13

Explanation: None

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

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

a. 11

b. 12
c. 13

d. 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

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

What will be the output?

a. 10, 10

b. 10, 11

c. 11, 10

d. 11, 11

Answer: (d) 11, 11

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

1. int * aPtr;
2. *aPtr = 100;
3. cout << *aPtr + 2;

a. 100

b. 102

c. 104

d. 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]?

1. char str[80];
2. char * p;
3. p = str;

a. p + 4

b. *p + 4

c. *(p + 4)

d. p [3]

Answer: (c) *(p + 4)


Explanation: None

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

1. int ** balance;

a. Balance is a point to an integer

b. Balance is a pointer to a pointer to an integer

c. Balance is a pointer to a pointer to a pointer to an integer

d. 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?

a. d = d;

b. b = d;

c. d = b;

d. *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. A pointer to an int and a pointer to a double are of the same size.

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

c. A pointer can be reassigned to point to another data item.

d. 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?

a. Stack

b. List

c. Deque

d. 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?

a. Forward iterator

b. Bi-directional iterator

c. Random access iterator

d. 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?

a. 2001

b. 2002

c. 2004

d. 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?

a. p1 = p1 + p2;

b. p1 = p1 - 9;

c. p2 = p2 + 9;

d. 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?

1. cPtr = cPtr + 5;

a. 305

b. 310

c. 320

d. 340

Answer: (a) 305

Explanation: cPtr = cPtr + 5

cPtr = 300 + 5

cPtr = 305

41) Which is valid expression in c language?

a. int my_num = 100,000;

b. int my_num = 100000;

c. int my num = 1000;

d. 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?
a. 27

b. 47

c. 69

d. 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?

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

a. a = 20, b = 20

b. a = 10, b = 20

c. a = 20, b = 10
d. 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?

a. Its value is defined within stdio.h

b. Its value is implementation dependent

c. Its value can be negative

d. Its value should not equal the integer equivalent of any character

e. All of the these

Answer: (e) All of the these

Explanation: All statements are true

45) What does this statement mean?

1. x - = y + 1;

a. x = x - y + 1

b. x = -x - y - 1

c. x = x + y - 1

d. 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

1. for (i = 3; i < 15; i + = 3)


2. {printf ("%d", i);
3. ++i;
4. }

What will be the output?

a. 3 6 9 12

b. 3 6 9 12 15

c. 3 7 11

d. 3 7 11 15

Answer: (c) 3 7 15

Explanation: None

47) Study the following statement

1. main()
2. {
3. char *s = "Hello,"
4. "World!";
5. printf("%s", s);
6. }

What will be the output?

a. Hello, World!

b. Hello,
World!

c. Hello

d. 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

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

Which of the following statement is correct?

a. num[9] is the last element of the array num

b. The value of num[8] is 3

c. The value of num[3] is 3

d. 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?

1. main()
2. {
3. printf ("\\n ab");
4. printf ("\\b si");
5. printf ("\\r ha");
6. }

a. absiha

b. asiha

c. haasi

d. 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?
1. void main()
2. {
3. int i = 065, j = 65;
4. printf ("%d %d", i, j);
5. }

a. 065 65

b. 53 65

c. 65 65

d. Syntax error

Answer: (b) 53 65

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

C Programming Interview Questions

1 What is the difference between a flowchart and an algorithm?


2. What are the features of the C programming language?
3. What are basic data types supported in the C Programming Language?
4. What are tokens in C?
5. What do you mean by the scope of the variable?
6. What are preprocessor directives in C?
7. What is the use of static variables in C?
8. What is the difference between malloc() and calloc() in C?
9. What do you mean by dangling pointers?
10. Write a program to convert a number to a string with the help of sprintf() function
11. What is recursion in C?
12. What is the difference between the local and global variables in C?
13. What are pointers and their uses?
14. What is typedef in C?
15. What are loops and how can we create an infinite loop in C?
16. What is the difference between type casting and type conversion?
17. What are header files and their uses?
18. What are the functions and their types?
19. What is the difference between macro and functions?
20. How to convert a string to numbers in C?
21. What are reserved keywords?
22. What is a structure?
23. What is union?
24. What is an r-value and value?
25. What is the difference between call by value and call by reference?
26. What is the sleep() function?
27. What are enumerations?
28: What is a volatile keyword?
29. Write a C program to print the Fibonacci series using recursion.
30. Write a C program to check whether a number is prime or not.
31. How is source code different from object code?
32. What is static memory allocation and dynamic memory allocation?
33. What is pass-by-reference in functions?
34. What is a memory leak and how to avoid it?
35. What are command line arguments?
36. What is an auto keyword?
37. Write a program to print “Hello-World” without using a semicolon.
38. Write a C program to swap two numbers without using a third variable.
39. Write a program to check whether a string is a palindrome or not.
40. Explain modifiers.
41. Write a program to print the factorial of a given number with the help of recursion.
42. Write a program to check an Armstrong number.
43. Write a program to reverse a given number.
44. What is the use of an extern storage specifier?
45. What is the use of printf() and scanf() functions in C Programming language?
46. What is near, far, and huge pointers in C?
47. Mention file operations in C.
48. Write a Program to check whether a linked list is circular or not.
49. Write a program to Merge two sorted linked lists.
50. What is the difference between getc(), getchar(), getch() and getche().

You might also like