Javatpoint Logo
Javatpoint Logo

C language MCQ

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

  1. -3.4e38 to 3.4e38
  2. -32767 to 32768
  3. -32668 to 32667
  4. -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:

What will be the output of this program?

  1. Wrong statement
  2. It will keep on printing javatpoint
  3. It will Print javatpoint once
  4. 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?

  1. The program must have at least one function.
  2. The program does not require any function.
  3. Input data
  4. 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. 4525
  2. 2525
  3. 4545
  4. 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?

  1. The opening parenthesis should immediately follow the macro name.
  2. There should be at least one blank between the macro name and the opening parenthesis.
  3. There should be only one blank between the macro name and the opening parenthesis.
  4. All the above comments are correct.

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

Explanation: None


6) What is a lint?

  1. C compiler
  2. Interactive debugger
  3. Analyzing tool
  4. 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++))"?

  1. The value of (a + 1)
  2. The current value of a
  3. Error message
  4. Garbage

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

Explanation: None


8) Study the following program:

If abcdefg is the input, the output will be

  1. abcd
  2. abc
  3. efg
  4. Garbage

Answer: (c) efg

Explanation: None


9) Study the following program:

What will be the output of this program?

  1. 6
  2. 9
  3. 12
  4. 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. X is a four-digit integer.
  2. X cannot be greater than a four-digit integer.
  3. X is a four-bit integer.
  4. 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?

  1. It reduces execution time.
  2. It reduces code size.
  3. It increases execution time.
  4. 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 _______.

  1. Before main
  2. After main
  3. Anywhere, but starting on a new line.
  4. 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. Forever
  2. Never
  3. 0
  4. 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?

  1. 1002
  2. 1004
  3. 1006
  4. 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. a = 10, c = 10
  2. a = 11, c = 10
  3. a = 10, c = 11
  4. 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?

  1. for
  2. while
  3. switch
  4. 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?

  1. The first object created is the first object destroyed; last created is last destroyed.
  2. The first object destroyed is the last object destroyed; last created is first destroyed.
  3. Objects are destroyed in the order they appear in memory, the object with the lowest memory address is destroyed first.
  4. 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. 18
  2. 19
  3. 20
  4. None of the these

Answer: (b) 20

Explanation: None


19) Directives are translated by the

  1. Pre-processor
  2. Compiler
  3. Linker
  4. 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?

  1. 0
  2. 1
  3. 2 or 4
  4. 10

Answer: (c) 2 or 4

Explanation: The int type takes 2 or 4 bytes.


21) What feature makes C++ so powerful?

  1. Easy implementation
  2. Reusing the old code
  3. Easy memory management
  4. 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?

  1. dest = src;
  2. dest == src;
  3. strcpy(dest, src);
  4. 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 ___.

  1. Extractor
  2. Inserter
  3. Manipulator
  4. 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

  1. Class interfaces
  2. Methods
  3. Return types
  4. 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. 1
  2. 10
  3. As per required
  4. 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. 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

Answer: (b) 39

Explanation: None


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

  1. 11
  2. 12
  3. 13
  4. 14

Answer: (c) 13

Explanation: None


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

  1. 11
  2. 12
  3. 13
  4. 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

What will be the output?

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

Answer: (d) 11, 11

Explanation: None


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

  1. 100
  2. 102
  3. 104
  4. 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. p + 4
  2. *p + 4
  3. *(p + 4)
  4. p [3]

Answer: (c) *(p + 4)

Explanation: None


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

  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

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?

  1. d = d;
  2. b = d;
  3. d = b;
  4. *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?

  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.

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?

  1. Stack
  2. List
  3. Deque
  4. 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?

  1. Forward iterator
  2. Bi-directional iterator
  3. Random access iterator
  4. 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?

  1. 2001
  2. 2002
  3. 2004
  4. 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?

  1. p1 = p1 + p2;
  2. p1 = p1 - 9;
  3. p2 = p2 + 9;
  4. 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. 305
  2. 310
  3. 320
  4. 340

Answer: (a) 305

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;

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?

  1. 27
  2. 47
  3. 69
  4. 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. a = 20, b = 20
  2. a = 10, b = 20
  3. a = 20, b = 10
  4. 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?

  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

Answer: (e) All of the these

Explanation: All statements are true


45) What does this statement mean?

  1. x = x - y + 1
  2. x = -x - y - 1
  3. x = x + y - 1
  4. 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

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

Answer: (c) 3 7 15

Explanation: None


47) Study the following statement

What will be the output?

  1. Hello, World!
  2. Hello,
    World!
  3. Hello
  4. 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

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

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. absiha
  2. asiha
  3. haasi
  4. 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. 065 65
  2. 53 65
  3. 65 65
  4. Syntax error

Answer: (b) 53 65

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


Next TopicC Tutorial




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA