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
Explanation
Dennis Ritchie created the C language at Bell Labs in the early 1970s. James Gosling created Java, Bjarne Stroustrup created C++, and Guido van Rossum created Python.


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
Explanation
C source files use the .c extension. .cpp is a C++ source file, .class is compiled Java bytecode, and .obj is an object file produced after compilation.


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

  1. *
  2. &
  3. ->
  4. %
Show Answer
Answer: b
Explanation
The address-of operator & returns the memory address of a variable. The * operator dereferences a pointer, -> accesses a structure member through a pointer, and % is the modulus operator.


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
Explanation
printf() is the standard C output function declared in <stdio.h>. System.out.println is Java, print is Python, and cout is 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
Explanation
%d (or %i) prints a signed decimal integer. %f is for floats, %c for a single character, and %s for a string.


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
Explanation
On a standard 32-bit (and 64-bit) compiler, int is 4 bytes (typically 32 bits). Note that the C standard only guarantees a minimum range — size is technically implementation-dependent.


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
Explanation
const makes a variable read-only after initialization. static controls storage duration/linkage, volatile tells the compiler the value may change unexpectedly, and register suggests storing the variable in a CPU register.


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
Explanation
C arrays are zero-indexed: the first element is at index 0, and the last element of an array of size n is at index n-1.


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
Explanation
<stdio.h> (standard input/output header) declares printf(), scanf(), fopen(), fclose() and related I/O functions. <stdlib.h> holds malloc/free/atoi, <string.h> holds strcpy/strlen, and <conio.h> is a non-standard console header.


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
Explanation
Returning 0 from main() tells the operating system that the program terminated successfully. Any non-zero value conventionally signals an error.


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
Explanation
2numbers is invalid because an identifier cannot begin with a digit. Identifiers may start with a letter or an underscore, followed by letters, digits or underscores.


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

  1. &
  2. *
  3. ->
  4. .
Show Answer
Answer: b
Explanation
The unary * operator dereferences a pointer, giving the value stored at the pointed-to address. & takes an address, -> accesses a struct member via pointer, and . accesses a member of a struct variable directly.


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

  1. alloc()
  2. malloc()
  3. new
  4. create()
Show Answer
Answer: b
Explanation
malloc() (memory allocation) reserves a block of bytes on the heap and returns a void pointer. new is a C++ operator; alloc() and create() are not standard C functions.


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

  1. clear()
  2. delete()
  3. free()
  4. release()
Show Answer
Answer: c
Explanation
free() returns heap memory obtained via malloc(), calloc() or realloc() back to the system. delete is the C++ counterpart of free().


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

  1. 3
  2. 3.33
  3. 1
  4. 0
Show Answer
Answer: c
Explanation
The modulus operator % returns the remainder of integer division. 10 ÷ 3 = 3 with a remainder of 1, so 10 % 3 = 1.


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

  1. ?:
  2. &&
  3. ||
  4. !=
Show Answer
Answer: a
Explanation
The ternary operator ?: is C’s only conditional selection operator — condition ? value_if_true : value_if_false. The others are logical and relational operators.


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
Explanation
// comment is the single-line comment introduced in C99. /* … */ is the classic multi-line comment, # is a preprocessor directive, and <!– –> is an HTML comment.


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

  1. 1
  2. 2
  3. 4
  4. Compiler dependent
Show Answer
Answer: a
Explanation
By definition in the C standard, sizeof(char) is always 1 byte. The number of bits in a byte may vary by platform, but sizeof(char) is fixed at 1.


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

  1. strcat()
  2. strcpy()
  3. strcmp()
  4. strlen()
Show Answer
Answer: b
Explanation
strcpy(dest, src) copies the source string (including the terminating ‘\0’) into the destination. strcat appends, strcmp compares, and strlen returns the length.


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
Explanation
In traditional C (C89), an unspecified return type implicitly defaults to int. This behaviour is disallowed in C99 and later, where every function must have an explicit return type.


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
Explanation
break immediately terminates the innermost loop or switch block. continue only skips to the next iteration, return exits the whole function, and exit() terminates the entire program.


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
Explanation
continue jumps straight to the loop’s next iteration, skipping any remaining statements in the current pass. break would exit the loop entirely.


23) What character terminates a standard C string?

  1. \n
  2. \0
  3. \t
  4. ;
Show Answer
Answer: b
Explanation
The null character ‘\0’ (ASCII value 0) marks the end of every C string. \n is a newline and \t is a tab — neither terminates a string.


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
Explanation
A null pointer is explicitly assigned NULL and points to no valid location. A wild pointer is uninitialized, a dangling pointer points to memory that has been freed, and a void pointer is a generic pointer type.


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

  1. strcat()
  2. strcmp()
  3. strlen()
  4. strcpy()
Show Answer
Answer: b
Explanation
strcmp(s1, s2) compares two strings character by character, returning 0 if equal, a negative value if s1 < s2, and a positive value if s1 > s2.


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
Explanation
<stdlib.h> declares the general utility functions: malloc(), calloc(), realloc(), free(), atoi(), exit() and rand().


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

  1. %s
  2. %c
  3. %d
  4. %f
Show Answer
Answer: b
Explanation
%c reads a single character. %s reads a whitespace-delimited string, %d reads an integer and %f reads a float.


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
Explanation
typedef creates an alias (a new name) for an existing type, e.g. typedef unsigned int uint;. struct, enum and union define new aggregate/composite types rather than aliases.


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
Explanation
In a struct, each member occupies its own distinct memory area (with possible padding for alignment), so all members can hold values simultaneously.


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
Explanation
In a union, all members share the same memory location — the union’s size equals that of its largest member. Only one member can hold a meaningful value at a time.


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

  1. .
  2. ->
  3. *
  4. &
Show Answer
Answer: b
Explanation
The arrow operator -> accesses a member through a pointer, e.g. ptr->name. It is shorthand for (*ptr).name. The dot operator is used with a struct variable directly.


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

  1. %d
  2. %i
  3. %f
  4. %p
Show Answer
Answer: c
Explanation
%f prints float/double values in decimal notation. %p prints a pointer address, while %d and %i print integers.


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

  1. #include
  2. #define
  3. #pragma
  4. #undef
Show Answer
Answer: b
Explanation
#define creates a macro or symbolic constant, e.g. #define PI 3.14159. #include pulls in a header, #undef removes a macro, and #pragma issues compiler-specific instructions.


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
Explanation
C performs no bounds checking on arrays. Reading or writing past the end causes undefined behavior — you may get garbage values, corrupt other memory, or crash. C has no exceptions.


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
Explanation
A variable declared inside a function or block has local (block) scope — it exists only within that block and is destroyed when the block exits.


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
Explanation
gets() / fgets() read an entire line including spaces. scanf(“%s”, …) stops at the first whitespace character, so it cannot read multi-word input.


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
Explanation
strlen() (from <string.h>) returns the number of characters before the terminating ‘\0’. For example, strlen(“Hello”) = 5.


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
Explanation
return exits a function and hands a value back to the caller. The other keywords are not part of C (yield is from Python/C#).


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
Explanation
A void* pointer is type-agnostic and can hold the address of any data type. It must be cast before dereferencing. This is why malloc() returns void*.


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
Explanation
When both operands are integers, integer division truncates the fractional part. 5 / 2 = 2, not 2.5. Use 5.0 / 2 to get a floating-point result.


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
Explanation
A static local variable is initialized only once and keeps its value between successive calls to the function. It has local scope but static (program-lifetime) storage duration.


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

  1. auto
  2. static
  3. extern
  4. register
Show Answer
Answer: a
Explanation
auto is the default storage class for variables declared inside a block — they are created on entry and destroyed on exit unless another storage class is specified.


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
Explanation
extern declares that a variable or function is defined in another translation unit (file), letting the linker resolve it. C has no global keyword.


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
Explanation
++i is pre-increment: i is incremented first, then the new value is used in the expression. i++ is post-increment: the current value is used first, then i is incremented.


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

  1. &&
  2. &
  3. |
  4. ^
Show Answer
Answer: b
Explanation
The single ampersand & performs a bitwise AND on each bit of two integers. The double ampersand && is the logical AND operator, | is bitwise OR and ^ is bitwise XOR.


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

  1. |
  2. ||
  3. !
  4. ^
Show Answer
Answer: b
Explanation
The double pipe || is the logical OR operator, returning 1 if either operand is true. The single pipe | is bitwise OR, ! is logical NOT and ^ is bitwise XOR.


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

  1. 0
  2. -1
  3. NULL
  4. Exception
Show Answer
Answer: c
Explanation
malloc() returns NULL when it cannot allocate the requested memory. Always check the returned pointer before using it — C does not throw exceptions.


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

  1. malloc()
  2. calloc()
  3. realloc()
  4. resize()
Show Answer
Answer: c
Explanation
realloc() changes the size of a previously allocated block, preserving existing contents (up to the smaller of the old and new sizes) and returning the new block’s address.


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
Explanation
calloc() takes the number of elements and the size of each, allocates the block and initializes all bytes to zero. malloc() takes a single byte count and leaves the memory uninitialized (garbage).


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
Explanation
“w” opens a file for writing, creating it if it does not exist and truncating it to zero length if it does. “r” is read-only, “a” appends and “rb” reads binary data.


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

  1. -1
  2. 0
  3. NULL
  4. EOF
Show Answer
Answer: c
Explanation
fopen() returns a NULL FILE pointer if the file cannot be opened (missing file, permission denied, etc.). Always test the return value before using the stream.


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
Explanation
fclose() flushes any buffered data and closes the FILE stream, releasing the associated resources. It returns 0 on success and EOF on error.


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
Explanation
EOF (End Of File) is a macro defined in <stdio.h>, typically with the value -1. Functions such as fgetc() and fscanf() return EOF when the end of the file is reached.


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
Explanation
<math.h> declares mathematical functions including sqrt(), pow(), sin(), cos(), log() and fabs(). On many systems you must link the math library with -lm.


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

  1. putchar()
  2. getchar()
  3. fputs()
  4. printf()
Show Answer
Answer: b
Explanation
getchar() reads one character from stdin and returns it as an int (or EOF). putchar() writes a character, fputs() writes a string and printf() writes formatted output.


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

  1. enum
  2. set
  3. list
  4. union
Show Answer
Answer: a
Explanation
enum defines a set of named integer constants, e.g. enum Color { RED, GREEN, BLUE };. union is a different construct where members share memory.


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
Explanation
The first enumerator defaults to 0, and each subsequent one increases by 1 (0, 1, 2, …) unless you assign explicit values.


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
Explanation
In C, relational and logical expressions yield the integer 1 for true and 0 for false. C (before C99’s <stdbool.h>) has no built-in boolean type.


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

  1. -1
  2. 0
  3. NULL
  4. NaN
Show Answer
Answer: b
Explanation
In C, 0 is false and any non-zero value is true. This applies to conditions in if, while, for and the logical operators.


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

  1. else
  2. otherwise
  3. default
  4. break
Show Answer
Answer: c
Explanation
The default label in a switch statement executes when no case label matches the switch expression. It is optional but recommended.


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
Explanation
Without a break, control falls through and the code for subsequent case labels executes as well, until a break or the end of the switch is reached.


62) What is the bitwise XOR operator in C?

  1. ~
  2. ^
  3. &
  4. |
Show Answer
Answer: b
Explanation
The caret ^ is the bitwise XOR operator: the result bit is 1 only when the two operand bits differ. ~ is NOT, & is AND and | is OR.


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

  1. !
  2. ~
  3. ^
  4. &
Show Answer
Answer: b
Explanation
The tilde ~ inverts every bit of its operand (one’s complement). The exclamation mark ! is the logical NOT, which returns 0 or 1.


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
Explanation
Shifting left by n bits (x << n) multiplies x by 2ⁿ, since each shift moves every bit to a higher place value. (Assuming no overflow.)


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
Explanation
Shifting right by n bits (x >> n) divides x by 2ⁿ, discarding the low-order bits. For unsigned values this is a logical shift (zero fill).


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

  1. strcpy()
  2. strcat()
  3. strtok()
  4. strdup()
Show Answer
Answer: b
Explanation
strcat(dest, src) appends a copy of src to the end of dest, overwriting dest’s terminating ‘\0’. strtok tokenizes a string and strdup duplicates it into new memory.


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
Explanation
Recursion is a function calling itself, with a base case to stop the recursion and a recursive case that moves toward the base case. Classic examples: factorial, Fibonacci, tree traversal.


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
Explanation
A dangling pointer still holds the address of memory that has already been freed (or of a variable that has gone out of scope). Dereferencing it is undefined behavior.


69) What is an uninitialized pointer called?

  1. Null pointer
  2. Wild pointer
  3. Dangling pointer
  4. Void pointer
Show Answer
Answer: b
Explanation
A wild pointer is declared but never initialized, so it contains an arbitrary address. Dereferencing it is undefined behavior — always initialize pointers to NULL or a valid address.


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

  1. fscanf()
  2. scanf()
  3. sscanf()
  4. read()
Show Answer
Answer: a
Explanation
fscanf() reads formatted data from any FILE stream. scanf() reads from stdin, sscanf() reads from a string, and read() is a low-level POSIX system call.


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

  1. fprintf()
  2. printf()
  3. sprintf()
  4. write()
Show Answer
Answer: a
Explanation
fprintf() writes formatted output to a specified FILE stream. printf() writes to stdout, sprintf() writes into a character buffer, and write() is a low-level system call.


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
Explanation
fflush() forces any buffered data in the stream to be written out (for output streams) and discards buffered input. Note that fflush(stdin) is technically undefined for input streams in standard C.


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
Explanation
The C standard does not fix a maximum number of array dimensions — the limit is imposed by the specific compiler and available memory, so it is effectively compiler-dependent.


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
Explanation
int *ptr; declares ptr as a pointer to an int. int ptr; is just an integer variable, and C has no reference-declaration syntax like int &ptr; (that is C++).


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
Explanation
The string literal “Hello” has 5 characters plus the terminating ‘\0’, so sizeof(“Hello”) = 6. (strlen(“Hello”) would return 5, since it stops before the null terminator.)


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
Explanation
int arr[5] = {0}; initializes all five elements to 0 — when a partial initializer is given, all remaining elements are set to zero. int arr[5]; leaves them uninitialized (garbage), and {1} sets only the first element to 1.


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
Explanation
%p is the format specifier for printing a pointer (memory address), usually shown in hexadecimal. %x prints an unsigned int in hex, and %a prints a float in hexadecimal form.


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

  1. ‘a’
  2. “a”
  3. a
  4. :a:
Show Answer
Answer: a
Explanation
‘a’ (single quotes) is a character constant of type char. “a” is a string literal (an array of 2 chars: ‘a’ and ‘\0’), and a bare a would be an identifier.


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

  1. \t
  2. \r
  3. \n
  4. \\
Show Answer
Answer: c
Explanation
\n is the newline escape sequence. \t is a tab, \r is a carriage return, and \\ produces a literal backslash.


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

  1. \a
  2. \t
  3. \b
  4. \v
Show Answer
Answer: b
Explanation
\t inserts a horizontal tab. \a is an alert (bell), \b is a backspace, and \v is a vertical tab.


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
Explanation
sizeof is a compile-time unary operator (not a function) that returns the size in bytes of a type or expression, e.g. sizeof(int) or sizeof arr.


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
Explanation
register hints to the compiler that the variable should be kept in a CPU register for faster access. It is only a suggestion — the compiler may ignore it. You cannot take the address of a register variable.


83) What is the format specifier for unsigned int?

  1. %d
  2. %u
  3. %ld
  4. %f
Show Answer
Answer: b
Explanation
%u prints an unsigned int. Using %d for an unsigned value can produce misleading results for large numbers. %ld is for long int.


84) What format specifier is used for long int?

  1. %d
  2. %ld
  3. %f
  4. %lu
Show Answer
Answer: b
Explanation
%ld prints a signed long int. %lu is for unsigned long, %d is for a plain int, and %f is for floating-point values.


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

  1. itoa()
  2. atoi()
  3. atof()
  4. strint()
Show Answer
Answer: b
Explanation
atoi() (ASCII to integer) converts a numeric string such as “123” into the int 123. atof() converts to a double, and itoa() is a non-standard reverse conversion.


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

  1. #define
  2. #include
  3. #import
  4. #use
Show Answer
Answer: b
Explanation
#include inserts the contents of a header file into the source before compilation, e.g. #include <stdio.h>. #import is an Objective-C / some-compiler extension, not standard C.


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
Explanation
The do-while loop executes its body first and then tests the condition, so the body always runs at least once. for and while loops test the condition before the first iteration.


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

  1. -5
  2. 0
  3. 1
  4. 5
Show Answer
Answer: b
Explanation
5 is non-zero, so it is true. The logical NOT operator ! inverts it to false, which is represented by 0.


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

  1. 0
  2. 1
  3. -1
  4. Error
Show Answer
Answer: b
Explanation
0 is false, so the logical NOT !0 yields true, which C represents as the integer 1.


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
Explanation
Both forms are used: void func(void) is the strict, unambiguous prototype meaning “takes no arguments”, while void func() is the older style that in C means “unspecified arguments”. In modern C the (void) form is preferred.


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
Explanation
Multiplication * and division / have higher precedence than addition + and subtraction –. So 2 + 3 * 4 evaluates as 2 + 12 = 14.


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
Explanation
volatile tells the compiler that the variable’s value may change at any time (e.g. by hardware, an interrupt or another thread), so it must not be cached in a register or optimized away. mutable is a C++ keyword.


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

  1. fseek()
  2. ftell()
  3. rewind()
  4. setpos()
Show Answer
Answer: a
Explanation
fseek(stream, offset, origin) moves the file position indicator to a specified byte offset from SEEK_SET, SEEK_CUR or SEEK_END. ftell() reports the current position and rewind() jumps to the beginning.


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
Explanation
ftell() returns the current value of the file position indicator as a long, measured in bytes from the beginning of the file. feof() only tests whether the end-of-file flag is set.


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
Explanation
rewind() moves the file position indicator back to the start of the file and also clears the error indicator for that stream.


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

  1. NIL
  2. NULL
  3. NONE
  4. 0x0
Show Answer
Answer: b
Explanation
NULL is the standard macro (defined in <stddef.h>, <stdio.h>, <stdlib.h> and others) that expands to a null pointer constant, typically ((void *)0).


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

  1. ->
  2. .
  3. *
  4. &
Show Answer
Answer: b
Explanation
The dot operator . accesses a member of a struct variable directly, e.g. emp.name. The arrow operator -> is used when you have a pointer to the struct.


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
Explanation
When an array is passed to a function, it decays to a pointer to its first element. The function therefore receives the address of the array, so modifications affect the original data.


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
Explanation
<limits.h> defines implementation limits for integer types such as INT_MAX, INT_MIN, CHAR_MAX, LONG_MAX and UINT_MAX. Floating-point limits (FLT_MAX, DBL_MIN) live in <float.h>.


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
Explanation
Applying ~ to 0 flips all 32 bits from 0 to 1, producing the all-ones pattern, which in two’s complement equals -1. In general, ~x = -(x + 1).
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