MCQS from C Programming Language set 26-50

 26. Which operator has the highest precedence?

A) +
B) *
C) ()
D) =
Answer: C) ()


27. What is the correct syntax to declare a function pointer?
A) int *func();
B) int (*func)();
C) int func*();
D) func int*();
Answer: B) int (*func)();


28. How do you allocate memory for an integer dynamically?
A) malloc(sizeof(int))
B) malloc(int)
C) alloc(int)
D) new int;
Answer: A) malloc(sizeof(int))


29. What is the default value of a global integer variable in C?
A) 0
B) Garbage value
C) Undefined
D) Compiler-dependent
Answer: A) 0


30. What will sizeof('A') return in C?
A) 1
B) 2
C) 4
D) Compiler-dependent
Answer: C) 4


31. What is the correct format specifier for long int?
A) %d
B) %ld
C) %li
D) Both B and C
Answer: D) Both B and C


32. What is the output of printf("%d", 10 / 3);?
A) 3.33
B) 3
C) 4
D) 0
Answer: B) 3


33. Which keyword is used to prevent modification of a variable?
A) static
B) const
C) volatile
D) immutable
Answer: B) const


34. Which function is used to read a single character from the user?
A) getchar()
B) scanf()
C) getch()
D) read()
Answer: A) getchar()


35. How do you write a single-line comment in C?
A) /* comment */
B) // comment
C) # comment
D) -- comment
Answer: B) // comment


36. How do you check if a file exists in C?
A) fexists("file.txt")
B) access("file.txt", F_OK)
C) file_exists("file.txt")
D) fopen("file.txt", "r") and check for NULL
Answer: D) fopen("file.txt", "r") and check for NULL


37. Which function is used to write a formatted string to a file?
A) printf()
B) fprintf()
C) writef()
D) fwritef()
Answer: B) fprintf()


38. What will be the output of printf("%c", 65);?
A) 65
B) A
C) Compilation error
D) Undefined behavior
Answer: B) A


39. What is a struct in C?
A) A data type for multiple variables
B) A class in C
C) A loop
D) A pointer
Answer: A) A data type for multiple variables


40. What does the continue statement do in a loop?
A) Exits the loop
B) Skips to the next iteration
C) Restarts the loop
D) Stops the program
Answer: B) Skips to the next iteration


41. What will sizeof(3.14) return?
A) 4
B) 8
C) 16
D) Compiler-dependent
Answer: B) 8


42. What is the return type of malloc()?
A) int*
B) void*
C) float*
D) char*
Answer: B) void*


43. What is the function of feof()?
A) Checks for end of file
B) Closes a file
C) Reads a file
D) Opens a file
Answer: A) Checks for end of file


44. Which function is used to move the file pointer?
A) seek()
B) fseek()
C) movefile()
D) filepos()
Answer: B) fseek()


45. What is a union in C?
A) A type storing different variables in the same memory location
B) A data structure
C) A function
D) A pointer
Answer: A) A type storing different variables in the same memory location


46. How do you declare a pointer to a function?
A) int (*ptr)();
B) int *ptr();
C) int &ptr();
D) function int*();
Answer: A) int (*ptr)();


47. What does return 0; mean in main()?
A) Indicates successful execution
B) Indicates failure
C) Nothing
D) Terminates the compiler
Answer: A) Indicates successful execution


48. Which statement about recursion is true?
A) A function calls itself
B) A function can’t call itself
C) It executes only once
D) It is only used in loops
Answer: A) A function calls itself


49. Which function is used to convert a string to an integer?
A) itoa()
B) atoi()
C) strtoi()
D) toint()
Answer: B) atoi()


50. What is the purpose of #pragma directive?
A) Provides additional compiler instructions
B) Defines a macro
C) Allocates memory
D) Declares a structure
Answer: A) Provides additional compiler instructions


Previous Post Next Post

نموذج الاتصال