ADVERTISEMENT
ADVERTISEMENT

C Programming Language MCQs

C is a general-purpose, procedural computer programming language, C language supports structured programming, lexical variable scope, and recursion, with a static type system. C language is used to develop software like operating systems, databases, compilers, and so on.

C language MCQs: This section contains multiple-choice questions and answers on the C programming language. It will help the students to test their skills and prepare well for their exams.

List of C programming MCQs

  1. C Basics MCQs
  2. C Data Types, Operators and Expressions MCQs
  3. C Conditional Statements MCQs
  4. C Control Statements MCQs
  5. C Strings MCQs
  6. C Arrays MCQs
  7. C Structures and Union MCQs
  8. C Functions MCQs
  9. C Pointers MCQs
  10. C File Handling MCQs
  11. C Preprocessor MCQs

1) C Basics MCQs

1. C language was developed by ___.

  1. Dennis Rechard
  2. Dennis M. Ritchie
  3. Bjarne Stroustrup
  4. Anders Hejlsberg

Answer: B) Dennis M. Ritchie

Explanation:

C programming language was developed by an American computer scientist Dennis M. Ritchie at Bell Laboratories (formerly AT&T Bell Laboratories).


2. In which year was C language developed?

  1. 1962
  2. 1978
  3. 1979
  4. 1972

Answer: D) 1972

Explanation:

C programming language was developed by Dennis Ritchie at Bell Laboratories in 1972.


3. C language is a successor to which language?

  1. Basic
  2. Cobol
  3. C++
  4. B

Answer: D) B

Explanation:

C programming language is a successor to the programming language B.


4. C is a ___.

  1. Low level language
  2. High level language
  3. Medium level language
  4. None of the above

Answer: C) Medium level language

Explanation:

C is a medium-level language because it contains the features of low-level language as well as high-level language.


5. How many keywords are there in C language?

  1. 32
  2. 33
  3. 64
  4. 18

Answer: A) 32

Explanation:

C language has only 32 keywords.


ADVERTISEMENT

6. C language is a ___.

  1. Procedural oriented programming language
  2. General purpose programming language
  3. Structured programming
  4. All of the above

Answer: D) All of the above

Explanation:

C programming language is a general-purpose, procedural computer programming language that supports structured programming also.


7. Which is not a valid keyword in C language?

  1. for
  2. while
  3. do-while
  4. switch

Answer: C) do-while

Explanation:

do-while is not a valid keyword in the C programming language. It's a control statement. 'do' and 'while' are the separate keywords. The rest of all 'for', 'while', and 'switch' are the valid keywords in C.


8. What is an identifier in C language?

  1. An identifier is a combination of alphanumeric characters used for conditional and control statements
  2. An identifier is a combination of alphanumeric characters used for any variable, function, label name
  3. Both A and B
  4. None of the above

Answer: B) An identifier is a combination of alphanumeric characters used for any variable, function, label name

Explanation:

An identifier is a combination of alphanumeric characters used for any variable, function, label name. An identifier is a name that is used to identify the variables/ constants, functions, arrays, label name, and user-defined data.


9. A C-style comment, simply surround the text with ___.

  1. /* and */
  2. // and //
  3. //
  4. /** and **/

Answer: A) /* and */

Explanation:

A C-style comment, simply surround the text with /* and */.


10. Can we place comments between the statement to comments a part of the code?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, we can place comments between the statement to comments a part of the code.

Example:

printf(/*"Hello World"*/ "Hey, how are you?");

ADVERTISEMENT

11. ___ is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard?

  1. C
  2. C++
  3. C89
  4. C99

Answer: D) C99

Explanation:

C99 is an informal name for ISO/IEC 9899:1999, a past version of the C programming language standard.


12. In which version of C language, the C++ Style comment (//) are introduced?

  1. C17
  2. C18
  3. C89
  4. C99

Answer: D) C99

Explanation:

C language version C99 introduced C++ style comment (//), they can be used to comment a single line.


13. The C source file is processed by the ___.

  1. Interpreter
  2. Compiler
  3. Both Interpreter and Compiler
  4. Assembler

Answer: B) Compiler

Explanation:

The C source file is processed by the compiler.


14. How many whitespace characters are allowed in C language?

  1. 2
  2. 3
  3. 4
  4. 5

Answer: D) 5

Explanation:

There are 5 whitespace characters are allowed in C language, they are:

  1. Space
  2. Horizontal tab
  3. Vertical tab
  4. Form feed
  5. New-line

15. How many punctuation characters are allowed in C language?

  1. 29
  2. 30
  3. 31
  4. 32

Answer: A) 29

Explanation:

There are 29 punctuation characters are allowed in C language, they are:

_ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " '

16. What is the extension of a C language source file?

  1. .c
  2. .cpp
  3. .c99
  4. .h

Answer: A) .c

Explanation:

The extension of a C language source file is ".c".


17. What is the extension of a C language header file?

  1. .c
  2. .cpp
  3. .c99
  4. .h

Answer: D) .h

Explanation:

The extension of a C language source file is ".h".


18. To develop which operating, C language was invented?

  1. Linux
  2. Unix
  3. Android
  4. Mac

Answer: B) Unix

Explanation:

C language was invented to develop Unix operating system.


19. Does C language support object-oriented approach?

  1. Yes
  2. No

Answer: B) No

Explanation:

C language does not support object-oriented approach.


20. Which is/are the disadvantage(s) of C language?

  1. No Garbage Collection
  2. Inefficient Memory Management
  3. Low level of abstraction
  4. Lack of Object Orientation
  5. All of the above

Answer: E) All of the above

Explanation:

The main disadvantages of C language are:

  1. No Garbage Collection
  2. Inefficient Memory Management
  3. Low level of abstraction
  4. Lack of Object Orientation

2) C Data Types, Operators and Expressions MCQs

21. Which are the fundamental data types in C?

  1. char
  2. int
  3. float
  4. All of the above

Answer: D) All of the above

Explanation:

The fundamental / basic data types in C language:

  • char
  • int
  • float

22. How many byte(s) does a char type take in C?

  1. 1
  2. 2
  3. 3
  4. 4

Answer: A) 1

Explanation:

The char data type takes one byte in the memory.


23. For which type, the format specifier "%i" is used?

  1. int
  2. char
  3. float
  4. double

Answer: A) int

Explanation:

In C programming language, both of the format specifier %d and %i are used for int type, where %d specifies the type of variable as decimal and %i specifies the type as integer.


24. What is the difference between float and double in C?

  1. both are used for the same purpose
  2. double can store just double value as compare to float value
  3. double is an enhanced version of float and was introduced in C99
  4. double is more precise than float and can store 64 bits

Answer: D) double is more precise than float and can store 64 bits

Explanation:

In C programming language, the double is more precise than float and can store 64 bits.


25. Which is the correct format specifier for double type value in C?

  1. %d
  2. %f
  3. %lf
  4. %LF

Answer: C) %lf

Explanation:

The %lf is used to represent a double type value in C programming language.


26. The short type represents ___.

  1. int
  2. float
  3. unsigned int
  4. short int

Answer: C) unsigned int

Explanation:

The short type represents short int in C language.


27. How many byte(s) does a short type take in C?

  1. 1
  2. 2
  3. 3
  4. 4

Answer: B) 2

Explanation:

In C programming language, the short or short int takes 2 bytes (16 bits) in memory.


28. What is the correct syntax to declare a variable in C?

  1. data_type variable_name;
  2. data_type as variable_name;
  3. variable_name data_type;
  4. variable_name as data_type;

Answer: A) data_type variable_name;

Explanation:

In C language, the correct syntax to declare a variable is:

data_type variable_name;

Where, data_type is the type of data (such as int, char, float, etc) and variable_name is a valid identifier. For example: int age;


29. How many types of qualifiers are there in C language?

  1. 2
  2. 3
  3. 4
  4. 5

Answer: B) 3

Explanation:

There are 3 types of qualifiers in C language, they are:


30. Which is/are the size qualifier(s) in C language?

  1. short
  2. long
  3. double
  4. Both A. and B

Answer: D) Both A. and B.

Explanation:

The size qualifiers are short and long.


31. Which is/are the sign qualifier(s) in C language?

  1. signed
  2. unsigned
  3. long
  4. Both A. and B

Answer: D) Both A. and B.

Explanation:

The sign qualifiers are used to specify the signed nature of an integer type. The sign qualifiers are signed and unsigned.


32. Which is/are the type qualifier(s) in C language?

  1. const
  2. volatile
  3. static
  4. Both A. and B

Answer: D) Both A. and B.

Explanation:

The type qualifiers are const and "volatile".


33. Which is correct with respect to the size of the data types in C?

  1. char > int > float
  2. char < int < float
  3. int < char < float
  4. int < chat > float

Answer: B) char < int < float

Explanation:

The correct order of the data types as per the size is: char < int > float.


34. Which operator is used to find the remainder of two numbers in C?

  1. /
  2. \
  3. %
  4. //

Answer: C) %

Explanation:

The % operator is known as "Modulus Operator" and it is used to find the remainder of two numbers.


35. Which of the following is not an arithmetic expression?

  1. x = 10
  2. x /= 10
  3. x %= 10
  4. x != 10

Answer: D) x != 10

Explanation:

x != 10 is not a valid arithmetic expression.


36. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    int x = 20;
    x %= 3;
    printf("%d",x);

    return 0;
}
  1. 2
  2. 2.5
  3. Error
  4. Warning

Answer: A) 2

Explanation:

In the above code, the value of x is 20 and then in the next statement, the expression is x %= 3. That will be evaluate as:

x %= 3;
x = x % 3;
x = 20 %3;
x = 2

37. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    float x = 21.0;
    x %= 3.0;
    printf("%f",x);

    return 0;
}
  1. 7
  2. 7.00
  3. 7.000000
  4. Error

Answer: D) Error

Explanation:

In the above code, we are performing modulus operation with float values. Modulus operator doesn't work with float and double operands. Thus, the output will be:

error: invalid operands to binary % (have ‘float’ and ‘double’)

38. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    float x = 23.456;
    printf("%.2f",x);
    return 0;
}
  1. 23.45600
  2. 23.456
  3. 23.45
  4. 23.46

Answer: D) 23.46

Explanation:

In the above code, the value of x is 23.456 and we are printing the value of x using the %.2f format specifier. %.2f rounds the value and prints the 2 digits after the decimal point.


39. What will be the output of the following C code?

#include <stdio.h>

void main()
{
    int x = 10;
    int y = x++ + 20;
    
    printf("%d,%d",x,y);
    
    return 0;
}
  1. 11,30
  2. 11,31
  3. 10,30
  4. 10,31

Answer: A) 11,30

Explanation:

In the above code, we are using a post-increment statement (x++), post-increment increases the value after evaluating the current expression. Thus, the value of y will be 30 and then x will be 11.


40. Increment (++) and decrement (--) are the ___ operators in C?

  1. Unary
  2. Binary
  3. Ternary
  4. None of the above

Answer: A) Unary

Explanation:

Increment (++) and decrement (--) are the unary operators. They need one operand to perform the operation.


41. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    unsigned char c=290;
    printf("%d",c);
    return 0;
}
  1. 290
  2. 256
  3. 34
  4. Garbage

Answer: C) 34

Explanation:

290 is beyond the range of unsigned char. Its corresponding value printed is: (290 % (UCHAR_MAX +1) where UCHAR_MAX represents highest (maximum) value of unsigned char type of variable. The value of UCHAR_MAX=255. Thus it prints 290 % (UCHAR_MAX+1)=34


42. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    int a=0;
    
    a=5||2|1;
    printf("%d",a);
    
    return 0;
}
  1. 1
  2. 7
  3. 0
  4. 8

Answer: A) 1

Explanation:

Bitwise OR operator (|) has precedence over logical OR operator (||). Thus the expression 5 || 2 | 1 is actually 5 || (2 |1).

Now,

2= 0000 0010
1= 0000 0001
2|1= 0000 0011=3
5 || 3 returns true as both are nonzero
Thus a=1

43. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    int x =-100;
    
    -100;
    printf("%d",x);
    
    return 0;
}
  1. 100
  2. -100
  3. 0
  4. Error

Answer: B) -100

Explanation:

The statement "-100;" is evaluated and this does not affect the value of "x".


44. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    int a,b,c;
    
    a=0x10; b=010;
    c=a+b;
    
    printf("%d",c);
    
    return 0;
}
  1. 20
  2. 24
  3. Garbage
  4. Error

Answer: B) 24

Explanation:

0x10 is hex value it's decimal value is 16 and 010 is an octal value it's decimal value is 8, hence answer will be 24.


45. Which C keyword is used to extend the visibility of variables?

  1. extend
  2. extends
  3. extern
  4. auto

Answer: C) extern

Explanation:

The "extern: keyword used to define an extern variable, that can be accessed in any source file. i.e., extern is used to extend the visibility of variables in C language.


46. What is the name of "&" operator in C?

  1. Ampersand
  2. And
  3. Address of
  4. None of the above

Answer: C) Address of

Explanation:

The "&" operator is known as 'Address Of' operator which is used to access the address of a variable.


C Conditional Statements MCQs

47. Which of the following are valid decision-making statements in C?

  1. if
  2. switch
  3. nested if
  4. All of these

Answer: D) All of these

Explanation:

All valid decision-making statements in C program are:

  • if statement
  • if-else statement
  • nested if statement
  • switch statement
  • nested switch statement

48. Decision making in the C programming language is ___.

  1. Repeating the same statement multiple times
  2. Executing a set of statements based on some condition
  3. Providing a name of the block of code
  4. All of these

Answer: B) Executing a set of statements based on some condition

Explanation:

Decision-making in C programming is executing a block of code to be executed by the program based on some condition.


49. Which of the following is a true value in C programming?

  1. 1
  2. "includehelp"
  3. ! NULL
  4. All of these

Answer: D) All of these

Explanation:

All non-zero and non-null values in C programming are true.


50. Ternary operator in C programming is ___.

  1. if-else-if
  2. ? :
  3. ? ; ?
  4. None of these

Answer: B) ? :

Explanation:

Ternary operator is used to execute expressions based on the given condition.


51. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    printf((43 > 43) ? "value 1 is greater!" : "value 1 is not greater!");
    return 0;
}
  1. value 1 is not greater
  2. value 1 is greater
  3. Error
  4. None of these

Answer: A) value 1 is not greater


52. What is the correct syntax of if statement in C program?

  1. if(condition){
    }
  2. if(condition) :
  3. If { [condition] }
  4. None of these

Answer: A)

if(condition){
}

Explanation:

The correct syntax of if statement in C program is:

if(condition){
    // code to be executed
}

53. The if statement is a conditional statement?

  1. True
  2. False

Answer: A) True

Explanation:

The if statement is a conditional statement, i.e., the block is executed based on the given condition.


54. When the condition of if statement is false, the flow of code will ___.

  1. go into the if block
  2. Exit the program
  3. Continue the code after skipping the if block
  4. None of these

Answer: C) Continue the code after skipping the if block

Explanation:

When the condition of if statement is false, the code after the if block will be executed and the if block code is skipped.


55. What will be the result of the following condition?

(! (25 > 25))
  1. True
  2. False
  3. Error
  4. None of these

Answer: A) True


56. Which statement is required to execute a block of code when the condition is false?

  1. for
  2. if
  3. else
  4. All of these

Answer: C) else

Explanation:

In the if-else block, the if block is executed when condition is True and else block is executed when condition is false.


57. Can the else statement exist without the if statement in C?

  1. Yes
  2. No

Answer: B) No

Explanation:

The else statement needs an if statement to execute the block.


58. Which of these if...else block syntax is correct?

  1. if(condition){
    }
    else {
    }
  2. if(condition){
    }
    else(condition){
    }
  3. if{
    }
    else {
    }
  4. None of these

Answer: A)

if(condition){
}
else {
}

Explanation:

The syntax of if...else block of code in C is:

if(condition){
    // true block
}
else {
    // false block
}

59. The if-elseif-else statement in C programming is used?

  1. Create multiple conditional statements
  2. Return values
  3. Loop in if-else block
  4. All of these

Answer: A) Create multiple conditional statements

Explanation:

The if-elseif-else statement is a statement which contains multiple statements based on conditions.


60. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    int marks = 43;
    
    if (marks > 90)
        printf("Grade : A ");
    else if (marks > 75)
        printf("Grade : B ");
    else if (marks > 60)
        printf("Grade : C ");
    if (marks > 40)
        printf("Grade : D ");
    else
        printf("Fail ");
    return 0;
}
  1. Grade : A
  2. Grade : B
  3. Grade : C
  4. Grade : D

Answer: D) Grade : D


61. How many expressions can be checked using if...elseif...else statement?

  1. 100
  2. 1
  3. Infinite
  4. None of these

Answer: C) Infinite

Explanation:

You can execute any number of expressions using if-elseif-else statements, each elseif statement containing one condition.


62. Is it possible to nest if-else statements in C programming?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Nesting of if-else statements in C programming is possible.


63. Which of the following syntax is correct for nested if-else statements?

  1. if(exp1){
    	if(exp2){
    	}
    }
    else {
    	if(exp3){
    	}
    }
  2. if(exp1){
    }else {
    }
    
  3. if{}
  4. None of these

Answer: A)

if(exp1){
	if(exp2){
	}
}
else {
	if(exp3){
	}
}

Explanation:

The correct syntax for nested if-else statements in C programming is:

if(exp1){
	if(exp2){
	}
}
else {
	if(exp3){
	}
}

64. What will be the output of the following C code?

#include <stdio.h>

int main(){
    int n = 65;
    if (n >= 75) {
        if (n >= 95) {
            printf("Excellent");
        }
        else
            printf("Pass");
    }
    else
        printf("Fail");
}
  1. Excellent
  2. Pass
  3. Fail
  4. None of these

Answer: C) Fail


65. Multiple values of the same variable can be tested using ___.

  1. switch
  2. for
  3. Function
  4. All of these

Answer: A) switch

Explanation:

The switch statement in C is used to test for multiple values of a variable.


66. Without a break statement in switch what will happen?

  1. All cases will work properly
  2. Cases will fall through after matching the first check
  3. Switch will throw error
  4. All of these

Answer: B) Cases will fall through after matching the first check

Explanation:

The break statement is used to terminate the current flow of code. And if it is not present in the switch statement, the cases will execute all cases after the matched case.


67. When all cases are unmatched which case is matched in a switch statement?

  1. Default case
  2. First case
  3. No case
  4. None of these

Answer: A) Default case

Explanation:

The default case of switch statement is executed when no other case is matched.


68. What will be the output of the following C code?

#include <stdio.h>

int main(){
    char grade = 'B';

    switch (grade) {
    case 'A':
        printf("Excellent!\n");
    case 'B':
    case 'C':
        printf("Well done\n");
    case 'D':
        printf("You passed\n");
    case 'F':
        printf("Better try again\n");
        break;
    default:
        printf("Invalid grade\n");
    }
}
  1. Well done
  2. You passed
  3. Better try again
  4. All of these

Answer: D) All of these

Explanation:

There is no break statement in case B, Case C, case D. the code will fall through executing all the print statements.


4) C Control Statements MCQs

69. Loops in C programming are used to ___.

  1. Execute a statement based on a condition
  2. Execute a block of code repeatedly
  3. Create a variable
  4. None of these

Answer: B) Execute a block of code repeatedly

Explanation:

Loops in programming are used to execute a block of code repeatedly.


70. Which of these is an exit-controlled loop?

  1. for
  2. if
  3. do...while
  4. while

Answer: C) do...while

Explanation:

The do...while loop check for a condition after executing the loop block once. Hence, it is called an exit-controlled loop.


71. Which statements are used to change the execution sequence?

  1. Loop control statement
  2. Function statement
  3. Conditional statement
  4. All of these

Answer: A) Loop control statement

Explanation:

Loop control statements in C are used to change the execution sequence of the loop.


72. What will happen if the loop condition will never become false?

  1. Program will throw an error
  2. Program will loop infinitely
  3. Loop will not run
  4. None of these

Answer: B) Program will loop infinitely

Explanation:

An infinite loop in a program is a condition when the loop continues when the loop continues to run infinitely because the condition never becomes false.


73. Which of these statements is correct in case of while loop in C?

  1. Executes the block till the condition become false
  2. Is an entry controlled loop
  3. There might be condition when the loop will not execute at all
  4. All of these

Answer: D) All of these

Explanation:

All of the above statements are true in the case of while loop. While loop is an entry-controlled loop, the block executes when the condition becomes false.


74. Which of the following is valid syntax for creating a while loop?

  1. while{
    } (condition)
    
  2. while(condition){
    }
    
  3. while{
    }
    
  4. All of these

Answer: B)

while(condition){
}

Explanation:

The correct syntax for creating a while loop is:

while(condition){
}

75. What will be the output of the following C code?

#include <stdio.h>

int main(){
    int a = 11;
    
    while (a < 20) {
        printf("%d  ", a);
        a += 2;
    }
    
    return 0;
}
  1. 11 13 15 17 19
  2. 11 12 13 14 15 16 17 18 19 20
  3. 11 13 15 17 19 21
  4. None of these

Answer: A) 11 13 15 17 19


76. Which loop executes the block a specific number of times?

  1. while loop
  2. for loop
  3. do...while loop
  4. All of these

Answer: B) for loop

Explanation:

The for loop executes the block a specific number of times.


77. Which of the following parts of the for loop can be eliminated in C?

  1. init
  2. condition
  3. increment
  4. All of these

Answer: D) All of these

Explanation:

Syntax of for loop:

for(init, condition, increment){
}

Inside the initialization statement (init), any of the three init or condition or increment can be eliminated i.e., all are optional. The loop can work without them also.


78. When all parts of the for loop are eliminated, what will happen?

  1. For loop will not work
  2. Infinite for loop
  3. Error
  4. None of these

Answer: B) Infinite for loop

Explanation:

On eliminating all the parts of a for loop an infinite for loop will run.


79. When the condition of the do-while loop is false, how many times will it execute the code?

  1. 0
  2. 1
  3. Infinite
  4. All of these

Answer: B) 1

Explanation:

The do-while loop is an exit-controlled loop, hence it will run at least once, even if the condition becomes false.


80. Can a loop be nested in C programming?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

Yes, the nesting of loop is possible in C programming language.


81. What will be the output of the following C code?

#include <stdio.h>

int main(){
    int i, j;

    for (i = 2; i < 10; i++) {
        for (j = 2; j <= (i / j); j++)
            if (!(i % j))
                break;
        if (j > (i / j))
            printf("%d ", i);
    }

    return 0;
}
  1. 2 3 4 5 6 7 8 9
  2. 3 5 7 9
  3. 2 3 5 7
  4. 2 3 5 7 11

Answer: C) 2 3 5 7


5) C Strings MCQs

82. A string is terminated by ___.

  1. Newline ('\n')
  2. Null ('\0')
  3. Whitespace
  4. None of the above

Answer: B) Null ('\0')

Explanation:

In C programming language, a string is a sequence of characters terminated with a null character \0.


83. Consider the below statement, can we assign a string to variable like this:

char c[100];
c = "C programming";
  1. Yes
  2. No

Answer: B) No

Explanation:

No, we cannot assign a string like this. Because string is a character array and array type is not assignable. To assign a string to the character array, we need to use strcpy() function.


84. Which format specifier is used to read and print the string using printf() and scanf() in C?

  1. %c
  2. %str
  3. %p
  4. %s

Answer: D) %s

Explanation:

The format specifier "%s" is used to read and print the string using printf() and scanf() in C.

Example:

#include <stdio.h>

int main()
{
    char name[30];

    printf("Input name: ");
    scanf("%s", name);
    printf("Given name is: %s", name);

    return 0;
}

/*
Output:
Input name: Alvin
Given name is: Alvin
*/

85. Which function is used to read a line of text including spaces from the user in C?

  1. scanf()
  2. getc()
  3. fgets()
  4. All of the above

Answer: C) fgets()

Explanation:

In C programming language, the fgets() function can be used to read a line of text including spaces from the user.

Syntax:

fgets(variable_name, sizeof(size), stdin);

86. Which function is used to concatenate two strings in C?

  1. concat()
  2. cat()
  3. stringcat()
  4. strcat()

Answer: D) strcat()

Explanation:

In C programming language, the strcat() function is used to concatenate two strings.

Syntax:

strcat(s1, s2);

This function concatenates string s2 onto the end of string s1.


87. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    char str1[] = { 'H', 'e', 'l', 'l', 'o' };
    char str2[] = "Hello";

    printf("%ld,%ld", sizeof(str1), sizeof(str2));

    return 0;
}
  1. 5,5
  2. 6,6
  3. 5,6
  4. None of the above

Answer: C) 5,6

Explanation:

str1 is initialized with the characters and there are only 5 characters. Thus, the length of the str is 5. While, str2 is initialized with the string "Hello", when we initialized the string in this way - a null ('\0') character is inserted after the string. Thus, the length of str2 is 6.


88. What will be the output of the following C code?

#include <stdio.h>

int main()
{
    char str1[] = "Hello";
    char str2[10];

    str2 = str1;

    printf("%s,%s", str1, str2);

    return 0;
}
  1. Hello,
  2. Hello,Hello
  3. Hello,HelloHello
  4. Error

Answer: D) Error

Explanation:

There will be a compilation error, because we cannot assign a string like this (str2 = str1). To resolve this issue, we have to use strcpy(str2,str1).

The output will be:

main.c:8:10: error: assignment to expression with array type
    8 |     str2 = str1;
      |          ^

89. What will be the output of the following C code? (If the input is "Hello world")

#include <stdio.h>

int main()
{
    char str[30];

    scanf("%s", str);
    printf("%s", str);

    return 0;
}
  1. Hello world
  2. Hello
  3. Hello world\0
  4. Error

Answer: B) Hello

Explanation:

When we read a string using the scanf() function, the input is terminated by the whitespace. Here, the input is "Hello world", so only "Hello" will be stored to str. Thus, the output will be "Hello".


90. Which function is used to compare two strings in C?

  1. strcmp()
  2. strcmpi()
  3. compare()
  4. cmpi()

Answer: A) strcmp()

Explanation:

The function strcmp() is used to compare two strings in C language.

The strcmp() is a built-in library function and is declared in <string.h> header file. This function takes two strings as arguments and compare these two strings lexicographically.

Syntax:

int strcmp(const char* str1, const char* str2);

91. Which function is used to compare two strings with ignoring case in C?

  1. strcmp()
  2. strcmpi()
  3. compare()
  4. cmpi()

Answer: B) strcmpi()

Explanation:

The function strcmpi() is used to compare two strings with ignoring case in C language.

The strcmpi() is a built-in library function and is declared in <string.h> header file. This function takes two strings as arguments and compare these two strings, it is similar to strcmp() function but the only difference is that strcmpi() function is not case sensitive.

Syntax:

int strcmpi(const char* str1, const char* str2);

6) C Arrays MCQs

92. Which is the correct syntax to declare an array in C?

  1. data_type array_name[array_size];
  2. data_type array_name{array_size};
  3. data_type array_name[];
  4. All of the above

Answer: A) data_type array_name[array_size];

Explanation:

The correct syntax to declare an array in C is:

data_type array_name[array_size];

93. You can access elements of an array by ___.

  1. values
  2. indices
  3. memory addresses
  4. All of the above

Answer: B) indices

Explanation:

You can access elements of an array by indices. Array indices starts from 0 to array_size -1.


94. Which is/are the correct syntax to initialize an array in C?

  1. data_type array_name[array_size] = {value1, value2, value3, …};
  2. data_type array_name[] = {value1, value2, value3, …};
  3. data_type array_name[array_size] = {};
  4. Both A and B

Answer: D) Both A and B

Explanation:

Both the options A and B are correct to initialize an array.

Example:

int mark[5] = {19, 10, 8, 17, 9};
// or
int mark[] = {19, 10, 8, 17, 9};

95. Array elements are always stored in ___ memory locations.

  1. Random
  2. Sequential
  3. Both A and B
  4. None of the above

Answer: B) Sequential

Explanation:

Array elements are always stored in sequential memory locations.


96. Let x is an integer array with three elements having value 10, 20, and 30. What will be the output of the following statement?

printf("%u",x);
  1. Prints the value of 0th element (i.e., 10)
  2. Prints the garbage value
  3. An error occurs
  4. Print the address of the array (i.e., the address of first (0th) element

Answer: D) Print the address of the array (i.e., the address of first (0th) element

Explanation:

If we print the array (in this case, x). The output will be the memory address of the array (i.e., the address of first (0th) element.


97. What will be the output of the following C program?

#include <stdio.h>

int main()
{
    int x[5] = { 10, 20, 30 };
    printf("%d", x[3]);
    return 0;
}
  1. 0
  2. 30
  3. Garbage value
  4. Error

Answer: A) 0

Explanation:

In C language, when an array is partially initialized at the time of declaration then the remaining elements of the array is initialized to 0 by default.


98. What will be the output of the following C program?

#include <stdio.h>

int main()
{
    int x[5] = { 10, 20, 30 };
    printf("%d", x[-1]);
    return 0;
}
  1. 0
  2. 10
  3. Garbage value
  4. Error

Answer: C) Garbage value

Explanation:

C language compiler does not check array with its bounds, when an index is out of the range the garbage value is printed.


99. What will be the output of the following C program?

#include <stdio.h>

int main()
{
    int x[5] = { 10, 20, 30 };
    printf("%ld", sizeof(x)/sizeof(x[0]));
    return 0;
}
  1. 3
  2. 4
  3. 5
  4. 6

Answer: C) 5

Explanation:

The statement sizeof(x)/sizeof(x[0]) can be used to get the total numbers of elements, sizeof(x) will return the size of array while sizeof(x[0]) will return the size of first element i.e., size of the type. Their division will return the total number of elements.


100. What will be the output of the following C program?

#include <stdio.h>

int main()
{
    int x[5] = { 10, 20, 30 };
    printf("%d", x[3]);
    return 0;
}
  1. 0
  2. 30
  3. Garbage value
  4. Error

Answer: A) 0

Explanation:

In C language, when an array is partially initialized at the time of declaration then the remaining elements of the array is initialized to 0 by default.


101. What will be the output of the following C program?

#include <stdio.h>

int main()
{
    int x[5] = { 10, 20, 30 };
    printf("%d", x[-1]);
    return 0;
}
  1. 0
  2. 10
  3. Garbage value
  4. Error

Answer: C) Garbage value

Explanation:

C language compiler does not check array with its bounds, when an index is out of the range the garbage value is printed.


102. If we pass an array as an argument to a function, what actually gets passed?

  1. Value of elements in array
  2. First element of the array
  3. Base address of the array i.e., the address of the first element
  4. Address of the last element of array

Answer: C) Base address of the array i.e., the address of the first element

Explanation:

If we pass an array as an argument to a function – the base address of the array (the address of the first element) is passed to the function.


7) C Structures and Union MCQs

103. Which of the following is the collection of different data types?

  1. structure
  2. string
  3. array
  4. All of the above

Answer: A) structure

Explanation:

In C programming language, a structure is a user-defined data type which is the collection of different data types.


104. Which operator is used to access the member of a structure?

  1. -
  2. >
  3. *
  4. .

Answer: D) .

Explanation:

The dot (.) operator is used to access the member of a structure.


105. Which of these is a user-defined data type in C?

  1. int
  2. union
  3. char
  4. All of these

Answer: B) union

Explanation:

Union is a user defined data type in C.


106. "A union can contain data of different data types". True or False?

  1. True
  2. False

Answer: A) True

Explanation:

Union is a user defined data structure which can store data variables of different data types.


107. Which keyword is used to define a union?

  1. un
  2. union
  3. Union
  4. None of these

Answer: B) union

Explanation:

The union is defined using the keyword union.


108. The size of a union is ___.

  1. Sum of sizes of all members
  2. Predefined by the compiler
  3. Equal to size of largest data type
  4. None of these

Answer: C) Equal to size of largest data type

Explanation:

The size of the union is equal to the size of the largest data type declared in the union.


109. All members of union ___.

  1. Stored in consecutive memory location
  2. Share same memory location
  3. Store at different location
  4. All of these

Answer: B) Share same memory location

Explanation:

All members of a union in C are stored at the same memory location.


110. Which of the below statements is incorrect in case of union?

  1. Union is a user-defined data structure
  2. All data share same memory
  3. Union stores methods too
  4. union keyword is used to initialize

Answer: C) Union stores methods too

Explanation:

Unions in C is a data structure which store data types but not the methods.


111. The members of union can be accessed using ___.

  1. Dot Operator (.)
  2. And Operator (&)
  3. Asterisk Operator (*)
  4. Right Shift Operator (>)

Answer: A) Dot Operator (.)

Explanation:

The dot operator (.) is used to access members of a union.


112. In which case union is better than structure?

  1. Less memory is available
  2. Faster compilation is required
  3. When functions are included
  4. None of these

Answer: A) Less memory is available


113. Which is the correct syntax to create a union?

  1. union union_name {
    };
  2. union union_name {
    }
  3. union union_name (
    );
  4. Union union_name (
    )

Answer: A)

union union_name {
};

Explanation:

The correct syntax of creating a union is:

union union_name {
};

114. What will be the output of the following C program?

#include <stdio.h>

union values {
    int val1;
    char val2;
} myVal;

int main()
{
    myVal.val1 = 66;
    
    printf("val1 = %p", &myVal.val1);
    printf("\nval2 = %p", &myVal.val2);
    
    return 0;
}
  1. val1 = 0x54ac88dd2012
    val2 = 0x55ac76dd2014
  2. Error
  3. val1 = 0x55ac76dd2014
    val2 = 0x55ac76dd2014
  4. Exception

Answer: C) val1 = 0x55ac76dd2014
val2 = 0x55ac76dd2014


8) C Functions MCQs

115. What is a function in C?

  1. User defined data type
  2. Block of code which can be reused
  3. Declaration syntax
  4. None of these

Answer: B) Block of code which can be reused

Explanation:

Function in C is a block of code which can be reused.


116. Functions in C can accept multiple parameters. True or False?

  1. True
  2. False

Answer: A) True

Explanation:

Functions in C programming can accept multiple parameters.


117. Which keyword is used to return values from function?

  1. Return
  2. Value
  3. Return type
  4. All of these

Answer: C) Return type

Explanation:

The return in declaration is initialized using return type.


118. Which of these is not a valid parameter passing method in C?

  1. Call by value
  2. Call by reference
  3. Call by pointer
  4. All of these

Answer: C) Call by pointer

Explanation:

Valid parameter passing method in C is:

  • Call by value
  • Call by reference

119. A C program contains ___.

  1. At least one function
  2. No function
  3. No value from command line
  4. All of these

Answer: A) At least one function

Explanation:

The main() function is required in the C program.


120. A recursive function in C ___.

  1. Call itself again and again
  2. Loop over a parameter
  3. Return multiple values
  4. None of these

Answer: A) Call itself again and again

Explanation:

Recursive function in C is a function which calls itself again and again.


121. The scope of a function is limited to?

  1. Current block
  2. Only function
  3. Whole file
  4. Directory

Answer: C) Whole file

Explanation:

The scope of a function is limited to the file it is declared in.


122. Which of the below syntax is the correct way of declaring a function?

  1. return function_name () {
    }
  2. data_type function_name (parameter) {
    }
  3. Void function_name (
    )
  4. None of these

Answer: B)

data_type function_name (parameter){
}

Explanation:

The correct syntax of declaring a function in C:

data_type function_name (parameter){
}

123. The sqrt() function is used to calculate which value?

  1. Square
  2. Square of reverse bits
  3. Square root
  4. None of these

Answer: C) Square root

Explanation:

The sqrt() method in C is used to calculate the square root of a number.


124. What will be the output of the following C program?

#include <stdio.h>

int myFunc(int x){
    return (--x);
}

int main(){
    int a = myFunc(13);
    printf("%d", a);
    return 0;
}
  1. 13
  2. 12
  3. 14
  4. Error

Answer: B) 12


9) C Pointers MCQs

125. Before using a pointer variable, it should be ___.

  1. Declared
  2. Initialized
  3. Both A. and B.
  4. None of the above

Answer: C) Both A. and B.

Explanation:

A pointer variable should be declared and initialized before the using.


126. An uninitialized pointer in C is called ___.

  1. Void pointer
  2. Empty pointer
  3. Invalid pointer
  4. Wild pointer

Answer: D) Wild pointer

Explanation:

An uninitialized pointer in C is called wild pointer. Since, the pointer is initialized it may lead a program to behave wrongly or to crash.


127. ___ is a pointer that occurs at the time when the object is de-allocated from memory without modifying the value of the pointer.

  1. Dangling pointer
  2. Wild pointer
  3. Void pointer
  4. Null pointer

Answer: A) Dangling pointer

Explanation:

A dangling pointer is a pointer that occurs at the time when the object is de-allocated from memory without modifying the value of the pointer.


128. A ___ can be assigned the address of any data type.

  1. Dangling pointer
  2. Wild pointer
  3. Void pointer
  4. Null pointer

Answer: C) Void pointer

Explanation:

A void pointer can be assigned the address of any data type.


129. Which pointer is called general-purpose pointer?

  1. Dangling pointer
  2. Wild pointer
  3. Void pointer
  4. Null pointer

Answer: C) Void pointer

Explanation:

A void pointer is called general-purpose, because it can be used with any type of variable.


130. Pointer arithmetic is not possible on ___.

  1. Integer pointers
  2. Float pointers
  3. Character pointers
  4. Void pointers

Answer: D) Void pointers

Explanation:

Pointer arithmetic is not possible on void pointers due to lack of concrete value and size.


131. Comment on the following pointer declaration?

int *p, x;
  1. p is a pointer to integer, x is not
  2. p and x, both are pointers to integer
  3. p is pointer to integer, x may or may not be
  4. p and x both are not pointers to integer

Answer: A) p is a pointer to integer, x is not

Explanation:

In the above given statement, variable p is a pointer to integer, while x is an integer variable.


132. What will be the output of the following C code?

#include <stdio.h>
int main(){
    int x = 10, *ptr;
    ptr = &x;
    *ptr = 20;
    printf("%d", x);
}
  1. 10
  2. 20
  3. Error
  4. A garbage value

Answer: B) 20

Explanation:

In the above program, x contains 10 and ptr is a pointer to x. We are changing the value of x with the help of pointer. Thus, the value will be changed and it will be 20.


133. What will be the output of the following C code?

#include <stdio.h>
int main(){
    char* ptr;
    ptr = "IncludeHelp";
    printf("%c", *&*ptr);
    return 0;
}
  1. IncludeHelp
  2. I
  3. Some address
  4. Error

Answer: B) I

Explanation:

In the above program, in printf statement – we are using two symbols those are * and &. The * is a dereference operator, and the & is a reference operator. These symbols can be used any number of times. Here ptr points to the first character in the string "IncludeHelp". *ptr dereferences it and so its value is I. Again & references it to an address and * dereferences it to the value I.


134. What is the correct syntax to declare pointer to pointer i.e., double pointer?

  1. type **pointer_name;
  2. type *&pointer_name;
  3. type *(*pointer_name);
  4. type **(pointer_name);

Answer: A) type **pointer_name;

Explanation:

The correct syntax syntax to declare pointer to pointer i.e., double pointer is:

type **pointer_name;

Example:

int **ptr; //declaration double pointer

135. What is ptr in the given statement?

int (*ptr)[5];
  1. ptr is an array of 5 pointers
  2. ptr is a simple integer array
  3. ptr is a pointer to a 5 elements integer array
  4. None of the above

Answer: C) ptr is a pointer to a 5 elements integer array

Explanation:

In the above statement, ptr is a pointer to a 5 elements integer array.


136. What is the correct syntax to declare a pointer to a constant?

  1. const type *pointer_name;
  2. type const *pointer_name;
  3. Both A. and B.
  4. None of the above

Answer: A) const type *pointer_name;

Explanation:

The correct syntax to declare a pointer to a constant is:

const type *pointer_name;

10) C File Handling MCQs

137. Which function is used to open a file in C?

  1. open()
  2. fopen()
  3. file_open()
  4. fileopen()

Answer: B) fopen()

Explanation:

In C programming language, the fopen() function is used to open a file.

Syntax:

ptr = fopen("fileopen","mode");

Where, fileopen is the name of the file, and mode is the mode of the file.


138. Which character(s) is/are used to open a binary file in append mode in C?

  1. a
  2. b
  3. ba
  4. ab

Answer: D) ab

Explanation:

The characters "ab" opens a binary file in append mode.

Syntax:

ptr = fopen("fileopen","ab");

139. Which character(s) is/are used to open a binary file in reading and writing mode in C?

  1. rw
  2. rwb
  3. rb+
  4. rwb

Answer: C) rb+

Explanation:

The characters "rb+" opens a binary file in reading and writing mode.

Syntax:

ptr = fopen("fileopen","rb+");

140. Which is the correct syntax to declare a file pointer in C?

  1. File *file_pointer;
  2. FILE *file_pointer;
  3. File file_pointer;
  4. FILE *file_pointer;

Answer: B) FILE *file_pointer;

Explanation:

The correct syntax to declare a file pointer in C is:

FILE *file_pointer;

141. Which function is used to close an opened file in C?

  1. close()
  2. fclose()
  3. file_close()
  4. fileclose()

Answer: B) fclose()

Explanation:

In C programming language, the fclose() function is used to close an opened file.

Syntax:

fclose(file_pointer);

142. Function fwrite() works with ___.

  1. Text files
  2. Binary files
  3. Both A. and B.
  4. None of the above

Answer: B) Binary files

Explanation:

Function fwrite() works with binary files. The file should be opened/created in binary mode.


143. What is the value of EOF in C?

  1. -1
  2. 0
  3. 1
  4. Null

Answer: A) -1

Explanation:

The EOF stands for End of File which is a Macro defined in stdio.h header file. With the GNU C Library, EOF is -1. In other libraries, its value may be some other negative number.


144. Which function checks the end-of-file indicator for the given stream in C?

  1. eof()
  2. EOF
  3. feof()
  4. None of the above

Answer: C) feof()

Explanation:

The C library function feof() checks the end-of-file indicator for the given stream.

Syntax:

int feof(FILE *stream);

145. Which function is used to seek the file pointer position in C?

  1. seek()
  2. fseek()
  3. fileseek()
  4. fmove()

Answer: B) fseek()

Explanation:

In C programming language, the fseek() function is used to seek the file pointer position.

Syntax:

int fseek(FILE *file_pointer, long int offset, int whence);

Where,

  • file_pointer− This is the pointer to a FILE object that identifies the stream.
  • offset − This is the number of bytes to offset from whence.
  • whence − This is the position from where offset is added, the value of this parameter may SEEK_SET, SEEK_CUR, or SEEK_END.

146. Which function is used to delete an existing file in C?

  1. delete()
  2. fremove()
  3. frem()
  4. remove()

Answer: D) remove()

Explanation:

In C programming language, the remove() function is used to delete an existing file.

Syntax:

int remove(const char *filename);

Where, filename is the name of the file to be removed.


11) C Preprocessor MCQs

147. What is CPP in C programming?

  1. C processing platform
  2. C PreProcessor
  3. C pre-platform
  4. None of these

Answer: B) C PreProcessor

Explanation:

In C programming, C preprocessors are referred to as CPP.


148. Which symbol is used to begin a preprocessor?

  1. @
  2. !
  3. #
  4. All of these

Answer: C) #

Explanation:

All preprocessor commands begin with a hash symbol (#).


149. Which of these is a valid preprocessor in C?

  1. #include
  2. #if
  3. #error
  4. All of these

Answer: D) All of these


150. (\) operator in C is ___.

  1. Macro continuation operator
  2. Stringize operator
  3. Tokenizer
  4. None of these

Answer: A) Macro continuation operator

Explanation:

Macro continuation (/) operator is used to continue a macro which is too long for a single line.


151. Which operator is used to stringize variables in C?

  1. /
  2. &
  3. *
  4. #

Answer: D) #

Explanation:

# Operator is used to stringize variables in C.


152. What will be the output of the following C code?

#include <stdio.h>

#define message_for(a, b) \
    printf("Learn " #a " programming language at " #b)

int main(void){
    message_for(python, includehelp);
    return 0;
}
  1. Learn python programming language at includehelp
  2. Learn #a programming language at #b
  3. Learn programming language at
  4. None of these

Answer: A) Learn python programming language at includehelp


153. Is it possible in a C program to merge two tokens into one token?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

The ### preprocessor in C is used to merge two tokens to one.


154. Which of these is not a valid preprocessor in C?

  1. \
  2. ?
  3. ###
  4. None of these

Answer: B) ?

Explanation:

\ and ### are both valid preprocessors in C.


155. Header files ___.

  1. Contain function declarations
  2. Can be included to a program
  3. End with .h extension
  4. All of these

Answer: D) All of these

Explanation:

All statements are correct. The header files are special files included in a program that contain functions and macros which can be imported and used in the code. The extension of header files is ".h".


156. Can programmers create their own header files?

  1. Yes
  2. No

Answer: A) Yes

Explanation:

A header file can be created by a programmer with some function that she needs to use in other files as well.


157. Which of these is valid syntax to include a header in C?

  1. #include <header>
  2. #include "header"
  3. Both A and B
  4. All of these

Answer: C) Both A and B

Explanation:

The valid syntaxes to include a header file to a program in C are:

  • #include <header>
  • #include "header"

158. What will happen if a header file is included in a program twice?

  1. Program will throw an error
  2. Program will throw an exception
  3. Program will run normally
  4. None of these

Answer: A) Program will throw an error

Explanation:

When the same header is included twice in the program, the compiler will throw an error as its teens to process it twice.


159. Which syntax is correct to include a specific preprocessor based on configuration?

  1. #defif system1 <system.h>
  2. #include system1 "system.h"
  3. import <system.h> if system1
  4. All of these

Answer: B) #include system1 "system.h"

Explanation:

The correct way to include a specific preprocessor based on configuration is known as computed include is:

#include system1 "system.h"

ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.