0% found this document useful (0 votes)
7 views

C Programming 70 MCQs

The document contains 70 multiple-choice questions (MCQs) related to C programming, aimed at BCA 1st semester students. Each question is followed by four answer options, with the correct answer indicated. Topics covered include language fundamentals, data types, control structures, functions, pointers, and file handling.

Uploaded by

jhas111003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

C Programming 70 MCQs

The document contains 70 multiple-choice questions (MCQs) related to C programming, aimed at BCA 1st semester students. Each question is followed by four answer options, with the correct answer indicated. Topics covered include language fundamentals, data types, control structures, functions, pointers, and file handling.

Uploaded by

jhas111003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

C Programming - 70 Important MCQs

for BCA 1st Semester’s Exam.


@tech.nap
1. Who developed the C language?

A) Dennis Ritchie
B) James Gosling
C) Bjarne Stroustrup
D) Guido van Rossum
Answer: A) Dennis Ritchie

2. C is a __________ programming language.

A) Object-oriented
B) Procedural
C) Functional
D) Logic-based
Answer: B) Procedural

3. Which is a valid C variable name?

A) 1name
B) name1
C) name@123
D) #name
Answer: B) name1

4. Which symbol is used to terminate a statement in C?

A) :
B) .
C) ;
D) ,
Answer: C) ;

5. What is the size of an integer in C (in bytes)?

A) 2
B) 4
C) Compiler-dependent
D) 8
Answer: C) Compiler-dependent

6. Which of the following is a loop control structure in C?

A) for
B) while
C) do-while
D) All of the above
Answer: D) All of the above

7. What is the output of if (0)?

A) True
B) False
C) Error
D) None
Answer: B) False

8. Which keyword is used to transfer control to the beginning of a loop?

A) break
B) continue
C) goto
D) return
Answer: B) continue

9. Which loop is guaranteed to execute at least once?

A) for
B) while
C) do-while
D) None of the above
Answer: C) do-while

10. Which of the following is not a jump statement in C?

A) break
B) continue
C) goto
D) switch
Answer: D) switch

11. Which function is used to print output in C?

A) print()
B) printf()
C) cin
D) cout
Answer: B) printf()

12. Which of the following is not a valid storage class in C?

A) auto
B) static
C) register
D) mutable
Answer: D) mutable

13. What is recursion in C?

A) Function calling itself


B) Function calling main
C) Function with infinite loops
D) None of the above
Answer: A) Function calling itself

14. Which header file is required for printf and scanf?

A) <conio.h>
B) <stdlib.h>
C) <stdio.h>
D) <math.h>
Answer: C) <stdio.h>

15. What is the return type of the main function in C?

A) int
B) void
C) float
D) None of the above
Answer: A) int

16. What does a pointer store?

A) Value of variable
B) Address of variable
C) Both A and B
D) None
Answer: B) Address of variable

17. Which operator is used to access the value at the address of a pointer?
A) *
B) &
C) ->
D) None
Answer: A) *

18. What will be the output of printf("%p", &x);?

A) Value of x
B) Address of x
C) Garbage value
D) Error
Answer: B) Address of x

19. Which of these is an invalid pointer declaration?

A) int *ptr;
B) float *ptr;
C) void ptr;
D) char *ptr;
Answer: C) void ptr

20. What does the NULL pointer represent?

A) Address 0
B) Garbage address
C) Undefined
D) None of the above
Answer: A) Address 0

21. What is the index of the first element in an array?

A) 0
B) 1
C) -1
D) None
Answer: A) 0

22. Which function is used to concatenate two strings?

A) strcat()
B) strcmp()
C) strlen()
D) strcpy()
Answer: A) strcat()

23. Which of the following is used to declare a 2D array?


A) int arr[10, 10];
B) int arr[10][10];
C) int arr(10, 10);
D) int arr{10, 10};
Answer: B) int arr[10][10];

24. How is a string stored in C?

A) Sequence of characters ending with ‘\0’


B) Sequence of integers
C) Sequence of floats
D) None of the above
Answer: A) Sequence of characters ending with ‘\0’

25. Which library is used for string handling?

A) <stdio.h>
B) <string.h>
C) <stdlib.h>
D) None
Answer: B) <string.h>

26. Which function is used to open a file in read mode?

A) fopen("file.txt", "r");
B) open("file.txt", "r");
C) file_open("file.txt");
D) None
Answer: A) fopen("file.txt", "r");

27. What is the return value of fopen() if the file cannot be opened?

A) EOF
B) NULL
C) 0
D) -1
Answer: B) NULL

28. Which function is used to read a character from a file?

A) fgetc()
B) fread()
C) getc()
D) All of the above
Answer: A) fgetc()

29. How do you close a file in C?


A) close()
B) fclose()
C) end()
D) None
Answer: B) fclose()

30. What does the fprintf() function do?

A) Writes formatted output to a file


B) Reads formatted input from a file
C) Both A and B
D) None
Answer: A) Writes formatted output to a file

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

A) open()
B) fopen()
C) fileopen()
D) None
Answer: B) fopen()

32. What is the file pointer returned by fopen() in C?

A) NULL
B) EOF
C) file pointer
D) None
Answer: A) NULL

33. Which of the following is correct for string in C?

A) Strings are enclosed in double quotes


B) Strings are enclosed in single quotes
C) Strings are arrays of characters
D) Both A and C
Answer: D) Both A and C

34. Which of the following statements is true about pointers?

A) A pointer holds the memory address of a variable


B) A pointer stores the value of a variable
C) A pointer does not require dereferencing
D) None of the above
Answer: A) A pointer holds the memory address of a variable

35. What is the purpose of the `sizeof()` operator?


A) To get the size of a variable in bits
B) To get the size of a variable in bytes
C) To get the value of a variable
D) To get the address of a variable
Answer: B) To get the size of a variable in bytes

36. Which keyword is used to prevent a function from modifying its arguments in C?

A) const
B) static
C) void
D) None
Answer: A) const

37. What will the following code output?


`printf('%d', sizeof(int));`

A) 2
B) 4
C) 8
D) Compiler-dependent
Answer: B) 4

38. Which of the following is a correct syntax for defining a 2D array?

A) int arr[10][20];
B) int arr(10, 20);
C) int arr{10, 20};
D) None
Answer: A) int arr[10][20];

39. What is the value of an uninitialized pointer?

A) 0
B) NULL
C) Garbage
D) Undefined
Answer: C) Garbage

40. Which function is used to get a string's length?

A) strlen()
B) strlength()
C) sizeof()
D) strlen_len()
Answer: A) strlen()
41. Which of the following is not a valid way to access the value of a pointer?

A) *ptr
B) ptr*
C) &ptr
D) All are valid
Answer: C) &ptr

42. What is the default return value of the `main()` function?

A) 0
B) 1
C) void
D) None
Answer: A) 0

43. What is the purpose of the `break` statement?

A) Exit a loop
B) Skip the remaining iteration
C) Continue the loop
D) None
Answer: A) Exit a loop

44. Which function is used to write a string to a file?

A) fwrite()
B) fprintf()
C) putchar()
D) None
Answer: B) fprintf()

45. What is the output of the following code snippet?


`printf('%d', 5 / 2);`

A) 2
B) 2.5
C) 0
D) 3
Answer: A) 2

46. Which of these cannot be used as a function argument?

A) Pointer
B) Array
C) Function
D) None
Answer: D) None

47. What is the role of the `fscanf()` function?

A) Read a single character from a file


B) Read formatted input from a file
C) Read the entire file
D) None
Answer: B) Read formatted input from a file

48. What is the size of a pointer variable in 64-bit systems?

A) 4 bytes
B) 8 bytes
C) 16 bytes
D) 32 bytes
Answer: B) 8 bytes

49. Which of the following is a valid way to return a value from a function?

A) return value;
B) return address;
C) return pointer;
D) All of the above
Answer: D) All of the above

50. What does the `continue` statement do inside a loop?

A) Terminates the loop


B) Skips the current iteration
C) Exits the program
D) None
Answer: B) Skips the current iteration

51. What is the use of the `void` keyword in C?

A) To declare an empty function


B) To declare a function that returns nothing
C) Both A and B
D) None
Answer: C) Both A and B

52. Which operator is used for bitwise AND in C?

A) &&
B) &
C) |
D) ^
Answer: B) &

53. What is the maximum value of an unsigned char?

A) 127
B) 255
C) 32767
D) 65535
Answer: B) 255

54. Which of the following operators has the highest precedence?

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

55. Which format specifier is used to print a float value?

A) %d
B) %f
C) %c
D) %s
Answer: B) %f

56. What does the `break` statement do in a switch-case structure?

A) Ends the entire program


B) Exits the switch block
C) Continues the next iteration
D) None
Answer: B) Exits the switch block

57. Which of the following is a valid declaration of a float variable?

A) int a;
B) float b;
C) double c;
D) char d;
Answer: B) float b;

58. How do you dynamically allocate memory for an array in C?


A) malloc()
B) calloc()
C) realloc()
D) Both A and B
Answer: D) Both A and B

59. What does the `return` statement do?

A) Exits a loop
B) Exits a function
C) Continues to the next iteration
D) None
Answer: B) Exits a function

60. What is the use of the `const` keyword in C?

A) To declare variables that cannot be modified


B) To initialize variables
C) To allocate memory
D) None
Answer: A) To declare variables that cannot be modified

61. Which function is used to allocate memory dynamically?

A) malloc()
B) calloc()
C) realloc()
D) All of the above
Answer: D) All of the above

62. What is a segmentation fault?

A) Accessing memory outside the allocated range


B) Infinite loop
C) Syntax error
D) None
Answer: A) Accessing memory outside the allocated range

63. What is the purpose of `#include` in C?

A) To include standard or user-defined files


B) To define macros
C) To start a comment
D) None
Answer: A) To include standard or user-defined files

64. Which of these is not a standard I/O function?


A) printf()
B) scanf()
C) gets()
D) putdata()
Answer: D) putdata()

65. What is the size of the `double` data type in most C compilers?

A) 4 bytes
B) 8 bytes
C) 2 bytes
D) Compiler-dependent
Answer: B) 8 bytes

66. What does `strcmp()` do in C?

A) Compares two strings


B) Copies two strings
C) Joins two strings
D) None
Answer: A) Compares two strings

67. Which library function is used to generate random numbers?

A) rand()
B) random()
C) randint()
D) None
Answer: A) rand()

68. How do you declare a pointer to a function?

A) int (*ptr)();
B) int *ptr();
C) int *(*ptr);
D) None
Answer: A) int (*ptr)();

69. Which is the default storage class in C?

A) auto
B) register
C) extern
D) static
Answer: A) auto
70. What will the following code output?
`printf("%d", sizeof('A'));`

A) 1
B) 2
C) 4
D) 8
Answer: C) 4

You might also like