100 C Programming MCQ (Multiple Choice Questions) with Answers

1) Who is known as the father of C programming language?
  1. James Gosling
  2. Dennis Ritchie
  3. Bjarne Stroustrup
  4. Guido van Rossum
Show Answer
Answer: b


2) Which of the following is the correct extension of a C source file?

  1. .c
  2. .cpp
  3. .class
  4. .obj
Show Answer
Answer: a


3) Which operator is used to get the memory address of a variable in C?

  1. *
  2. &
  3. ->
  4. %
Show Answer
Answer: b


4) What is the correct syntax to output “Hello World” in C?

  1. System.out.println(“Hello World”);
  2. print(“Hello World”);
  3. printf(“Hello World”);
  4. cout << “Hello World”;
Show Answer
Answer: c


5) Which format specifier is used to print an integer in printf()?

  1. %f
  2. %c
  3. %d
  4. %s
Show Answer
Answer: c


6) What is the size of int data type in standard 32-bit C compiler?

  1. 1 byte
  2. 2 bytes
  3. 4 bytes
  4. 8 bytes
Show Answer
Answer: c


7) Which keyword is used to declare a variable whose value cannot be changed?

  1. static
  2. const
  3. volatile
  4. register
Show Answer
Answer: b


8) What is the index of the first element in a C array?

  1. 1
  2. -1
  3. 0
  4. Depends on array size
Show Answer
Answer: c


9) Which header file is required to use printf() and scanf() functions?

  1. <stdlib.h>
  2. <conio.h>
  3. <stdio.h>
  4. <string.h>
Show Answer
Answer: c


10) What does the main() function return by default to indicate successful execution?

  1. -1
  2. 1
  3. 0
  4. NULL
Show Answer
Answer: c


11) Which of the following is NOT a valid C variable name?

  1. int_count
  2. _value
  3. 2numbers
  4. totalSum
Show Answer
Answer: c


12) Which operator is used to dereference a pointer in C?

  1. &
  2. *
  3. ->
  4. .
Show Answer
Answer: b


13) What function is used to dynamically allocate memory in C?

  1. alloc()
  2. malloc()
  3. new
  4. create()
Show Answer
Answer: b


14) Which function is used to free dynamically allocated memory?

  1. clear()
  2. delete()
  3. free()
  4. release()
Show Answer
Answer: c


15) What will 10 % 3 evaluate to in C?

  1. 3
  2. 3.33
  3. 1
  4. 0
Show Answer
Answer: c


16) Which of the following is a conditional selection operator in C?

  1. ?:
  2. &&
  3. ||
  4. !=
Show Answer
Answer: a


17) How do you write a single-line comment in modern C (C99 onwards)?

  1. /* comment */
  2. # comment
  3. // comment
  4. <!– comment –>
Show Answer
Answer: c


18) What is the output of sizeof(char) in C?

  1. 1
  2. 2
  3. 4
  4. Compiler dependent
Show Answer
Answer: a


19) Which library function is used to copy one string to another?

  1. strcat()
  2. strcpy()
  3. strcmp()
  4. strlen()
Show Answer
Answer: b


20) What is the default return type of a function in C if not specified?

  1. void
  2. float
  3. int
  4. char
Show Answer
Answer: c


21) Which keyword is used to exit from a loop or switch block immediately?

  1. continue
  2. return
  3. break
  4. exit
Show Answer
Answer: c


22) Which statement skips the remaining code in the current iteration of a loop?

  1. break
  2. skip
  3. continue
  4. pass
Show Answer
Answer: c


23) What character terminates a standard C string?

  1. \n
  2. \0
  3. \t
  4. ;
Show Answer
Answer: b


24) What is a pointer that points to no valid memory location called?

  1. Wild pointer
  2. Void pointer
  3. Null pointer
  4. Dangling pointer
Show Answer
Answer: c


25) Which function is used to compare two strings in C?

  1. strcat()
  2. strcmp()
  3. strlen()
  4. strcpy()
Show Answer
Answer: b


26) Which header file is required for functions like malloc() and free()?

  1. <stdio.h>
  2. <stdlib.h>
  3. <math.h>
  4. <string.h>
Show Answer
Answer: b


27) What is the format specifier for a single character in scanf()?

  1. %s
  2. %c
  3. %d
  4. %f
Show Answer
Answer: b


28) Which keyword is used to create a custom type name in C?

  1. struct
  2. typedef
  3. enum
  4. union
Show Answer
Answer: b


29) In a struct, how are members stored in memory?

  1. All members share the same memory location
  2. Each member has its own separate memory area
  3. Dynamically allocated on heap
  4. In reverse order
Show Answer
Answer: b


30) In a union, how are members stored in memory?

  1. Each member has separate memory
  2. All members share the same memory location
  3. Stored in array format
  4. Stored in binary tree format
Show Answer
Answer: b


31) What operator is used to access structure members using a structure pointer?

  1. .
  2. ->
  3. *
  4. &
Show Answer
Answer: b


32) What is the format specifier used for printing floating-point numbers?

  1. %d
  2. %i
  3. %f
  4. %p
Show Answer
Answer: c


33) Which preprocessor directive is used to define symbolic constants in C?

  1. #include
  2. #define
  3. #pragma
  4. #undef
Show Answer
Answer: b


34) What will happen if you access an array out of its defined bounds in C?

  1. Compile-time error
  2. Undefined behavior / garbage value
  3. Automatic array extension
  4. Program throws an Exception
Show Answer
Answer: b


35) What is the scope of a variable declared inside a function block?

  1. Global scope
  2. File scope
  3. Local scope
  4. Universal scope
Show Answer
Answer: c


36) Which function is used to read a string with spaces from standard input?

  1. scanf(“%s”, str)
  2. gets() / fgets()
  3. getc()
  4. read()
Show Answer
Answer: b


37) What function is used to calculate the length of a string in C?

  1. length()
  2. size()
  3. strlen()
  4. strlength()
Show Answer
Answer: c


38) Which keyword is used to pass back a value from a function?

  1. return
  2. yield
  3. send
  4. back
Show Answer
Answer: a


39) What is a generic pointer in C that can point to data of any type?

  1. int*
  2. char*
  3. void*
  4. NULL
Show Answer
Answer: c


40) What is the output of printf(“%d”, 5 / 2); in integer arithmetic?

  1. 2.5
  2. 2
  3. 3
  4. 2.0
Show Answer
Answer: b


41) Which storage class retains a local variable’s value between function calls?

  1. auto
  2. register
  3. static
  4. extern
Show Answer
Answer: c


42) What is the default storage class for local variables in C?

  1. auto
  2. static
  3. extern
  4. register
Show Answer
Answer: a


43) Which keyword is used to declare a variable defined in another file?

  1. static
  2. extern
  3. register
  4. global
Show Answer
Answer: b


44) What does the operator ++i do compared to i++?

  1. Increments after using the value
  2. Increments before using the value
  3. Decrements before using
  4. Multiplies by 2
Show Answer
Answer: b


45) Which of the following is a bitwise AND operator in C?

  1. &&
  2. &
  3. |
  4. ^
Show Answer
Answer: b


46) Which of the following is a logical OR operator in C?

  1. |
  2. ||
  3. !
  4. ^
Show Answer
Answer: b


47) What will malloc() return if memory allocation fails?

  1. 0
  2. -1
  3. NULL
  4. Exception
Show Answer
Answer: c


48) What function reallocates memory to a new size in C?

  1. malloc()
  2. calloc()
  3. realloc()
  4. resize()
Show Answer
Answer: c


49) What is the primary difference between malloc() and calloc()?

  1. calloc() initializes memory to zero, while malloc() leaves garbage values
  2. malloc() is faster
  3. malloc() is for arrays, calloc() is for single variables
  4. There is no difference
Show Answer
Answer: a


50) Which mode is used in fopen() to open a file for writing, creating it if it doesn’t exist?

  1. “r”
  2. “w”
  3. “a”
  4. “rb”
Show Answer
Answer: b


51) What does fopen() return if the file cannot be opened?

  1. -1
  2. 0
  3. NULL
  4. EOF
Show Answer
Answer: c


52) Which function is used to close an open file in C?

  1. close()
  2. fclose()
  3. file_close()
  4. end()
Show Answer
Answer: b


53) What constant represents the end of a file in C standard I/O?

  1. NULL
  2. EOF
  3. END
  4. -1
Show Answer
Answer: b


54) Which header file contains math functions like sqrt() and pow()?

  1. <stdlib.h>
  2. <stdio.h>
  3. <math.h>
  4. <complex.h>
Show Answer
Answer: c


55) Which of these functions reads a single character from standard input?

  1. putchar()
  2. getchar()
  3. fputs()
  4. printf()
Show Answer
Answer: b


56) What keyword is used to define an enumeration data type?

  1. enum
  2. set
  3. list
  4. union
Show Answer
Answer: a


57) By default, what integer value is assigned to the first item in an enum?

  1. 1
  2. -1
  3. 0
  4. NULL
Show Answer
Answer: c


58) What is the result of 5 == 5 in a C condition evaluation?

  1. true
  2. 1
  3. 0
  4. yes
Show Answer
Answer: b


59) What value represents “false” in traditional C boolean evaluation?

  1. -1
  2. 0
  3. NULL
  4. NaN
Show Answer
Answer: b


60) Which keyword is used in switch-case to handle unmatched values?

  1. else
  2. otherwise
  3. default
  4. break
Show Answer
Answer: c


61) What happens if a break statement is omitted at the end of a case in switch?

  1. Compiler error
  2. Execution falls through to subsequent cases
  3. Loop terminates
  4. Switch resets
Show Answer
Answer: b


62) What is the bitwise XOR operator in C?

  1. ~
  2. ^
  3. &
  4. |
Show Answer
Answer: b


63) What is the bitwise NOT (complement) operator in C?

  1. !
  2. ~
  3. ^
  4. &
Show Answer
Answer: b


64) What does the left shift operator << do to an integer?

  1. Multiplies it by powers of 2
  2. Divides it by powers of 2
  3. Adds 2
  4. Negates the number
Show Answer
Answer: a


65) What does the right shift operator >> do to a positive integer?

  1. Multiplies it by 2
  2. Divides it by powers of 2
  3. Subtracts 2
  4. Rotates bits
Show Answer
Answer: b


66) What function appends one string to the end of another?

  1. strcpy()
  2. strcat()
  3. strtok()
  4. strdup()
Show Answer
Answer: b


67) What is a recursion in C?

  1. A loop inside a loop
  2. A function calling itself
  3. Calling a function from another file
  4. Dynamic memory allocation
Show Answer
Answer: b


68) What is a pointer pointing to a memory location that has been freed called?

  1. Null pointer
  2. Dangling pointer
  3. Wild pointer
  4. Void pointer
Show Answer
Answer: b


69) What is an uninitialized pointer called?

  1. Null pointer
  2. Wild pointer
  3. Dangling pointer
  4. Void pointer
Show Answer
Answer: b


70) Which function reads formatted input from a file stream?

  1. fscanf()
  2. scanf()
  3. sscanf()
  4. read()
Show Answer
Answer: a


71) Which function writes formatted output to a file stream?

  1. fprintf()
  2. printf()
  3. sprintf()
  4. write()
Show Answer
Answer: a


72) What is the purpose of fflush(stdin) or fflush(stdout)?

  1. Clears the screen
  2. Flushes the stream buffer
  3. Closes the stream
  4. Allocates buffer memory
Show Answer
Answer: b


73) What is the maximum number of dimensions an array can have in C?

  1. 2
  2. 3
  3. 32
  4. Compiler-dependent (conceptually unlimited)
Show Answer
Answer: d


74) How do you declare a pointer to an integer in C?

  1. int ptr;
  2. int *ptr;
  3. ptr int;
  4. int &ptr;
Show Answer
Answer: b


75) What is the output of sizeof(“Hello”) in bytes (including null terminator)?

  1. 5
  2. 6
  3. 4
  4. 8
Show Answer
Answer: b


76) Which statement creates an array of 5 integers initialized to zero?

  1. int arr[5];
  2. int arr[5] = {0};
  3. int arr[5] = {1};
  4. int arr = new int[5];
Show Answer
Answer: b


77) What is the format specifier for printing pointer address in hexadecimal format?

  1. %x
  2. %p
  3. %d
  4. %a
Show Answer
Answer: b


78) Which of these is a valid character constant in C?

  1. ‘a’
  2. “a”
  3. a
  4. :a:
Show Answer
Answer: a


79) What is the escape sequence for a new line in C?

  1. \t
  2. \r
  3. \n
  4. \\
Show Answer
Answer: c


80) What is the escape sequence for a tab space?

  1. \a
  2. \t
  3. \b
  4. \v
Show Answer
Answer: b


81) What operator is used to calculate the size of a data type or variable in bytes?

  1. size()
  2. sizeof()
  3. len()
  4. length()
Show Answer
Answer: b


82) Which of the following storage classes requests the compiler to store the variable in CPU register?

  1. static
  2. register
  3. auto
  4. extern
Show Answer
Answer: b


83) What is the format specifier for unsigned int?

  1. %d
  2. %u
  3. %ld
  4. %f
Show Answer
Answer: b


84) What format specifier is used for long int?

  1. %d
  2. %ld
  3. %f
  4. %lu
Show Answer
Answer: b


85) What function converts a string of digits into an integer?

  1. itoa()
  2. atoi()
  3. atof()
  4. strint()
Show Answer
Answer: b


86) What is the preprocessor directive used to include header files?

  1. #define
  2. #include
  3. #import
  4. #use
Show Answer
Answer: b


87) Which loop tests the exit condition at the bottom after executing the loop body once?

  1. for loop
  2. while loop
  3. do-while loop
  4. nested loop
Show Answer
Answer: c


88) What is the output of !5 in C logical evaluation?

  1. -5
  2. 0
  3. 1
  4. 5
Show Answer
Answer: b


89) What is the output of !0 in C?

  1. 0
  2. 1
  3. -1
  4. Error
Show Answer
Answer: b


90) How is a function defined as receiving no arguments in C?

  1. void func(void)
  2. void func()
  3. func(null)
  4. Both a and b
Show Answer
Answer: d


91) What is the precedence order of arithmetic operators *, /, +, -?

  1. + and – have higher precedence than * and /
  2. * and / have higher precedence than + and –
  3. All four have equal precedence
  4. Left-to-right evaluation without precedence rules
Show Answer
Answer: b


92) What keyword is used to specify that a variable can be modified unexpectedly by hardware/threads?

  1. static
  2. const
  3. volatile
  4. mutable
Show Answer
Answer: c


93) What function moves the file position pointer to a specific location?

  1. fseek()
  2. ftell()
  3. rewind()
  4. setpos()
Show Answer
Answer: a


94) What function returns the current file pointer position in a file stream?

  1. fseek()
  2. ftell()
  3. fgetpos()
  4. feof()
Show Answer
Answer: b


95) What function resets the file position pointer back to the beginning of the file?

  1. reset()
  2. restart()
  3. rewind()
  4. clear()
Show Answer
Answer: c


96) What standard macro in C denotes a null pointer constant?

  1. NIL
  2. NULL
  3. NONE
  4. 0x0
Show Answer
Answer: b


97) What operator is used to access structure members using a structure variable directly?

  1. ->
  2. .
  3. *
  4. &
Show Answer
Answer: b


98) Which statement is true regarding C array parameters in functions?

  1. Arrays are always passed by value
  2. Arrays are decayed to pointers and passed by reference/address
  3. Arrays cannot be passed to functions
  4. Array size must be constant at compile time
Show Answer
Answer: b


99) Which header file contains macro definitions like INT_MAX and INT_MIN?

  1. <float.h>
  2. <limits.h>
  3. <stdlib.h>
  4. <math.h>
Show Answer
Answer: b


100) What is the result of applying bitwise NOT (~) on 0 in 32-bit two’s complement integer representation?

  1. 0
  2. 1
  3. -1
  4. INT_MAX
Show Answer
Answer: c

 

100 Java MCQ (Multiple Choice Questions) with Answers
100 C++ MCQ (Multiple Choice Questions) with Answers
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment