C programming language
C programming language is a powerful, general-purpose language widely used for system and application software development. Known for its efficiency and flexibility, C enables low-level memory manipulation, making it ideal for developing operating systems, embedded systems, and high-performance applications. Key features include a rich set of operators, control structures, and data types, allowing for structured and procedural programming. C is also the foundation for many other languages like C++, C#, and Java. Learning C is essential for understanding computer science fundamentals and enhancing programming skills.
Click Here for Service if you need
SEO Keywords: C programming language, system software development, low-level memory manipulation, structured programming, procedural programming, C language features, C programming fundamentals, application software development, embedded systems, high-performance applications, learn C programming, programming languages, computer science fundamentals.
MCQs in C programming
Here are 50 multiple-choice questions (MCQs) on C programming, along with their answers:
Generated and compiled by Md Farrukh Asif
===================================================================
1. Which of these is a valid comment in C?
- A)
// This is a comment - B)
/* This is a comment - C)
*/ This is a comment - D)
# This is a comment - **Answer**
: (A)// This is a comment
2. If you want to print a floating-point number, which format specifier
should you use?
- A)
%d - B)
%c - C)
%f - D)
%s - **Answer**
: (C)%f
3. How do you correctly declare a pointer in C?
- A)
int *ptr; - B)
int ptr*; - C)
*int ptr; - D)
int ptr; - **Answer**
:: (A)int *ptr;
4. What will be the result of printf("%d", 5+7);?
- A) 5
- B) 7
- C) 12
- D) Undefined
- **Answer**
:: C) 12
5. Which operator do you use to get the value stored at a pointer's
address?
- A)
& - B)
* - C)
-> - D)
[] - **Answer**
:: B)*
6. Which data type typically occupies 4 bytes in C?
- A)
char - B)
int - C)
float - D)
double - **Answer**
:: B)int
7. What does the following code print?
printf("%d", x++);
- A) 5
- B) 6
- C) 0
- D) Compilation Error
- **Answer**
: (A) 5
8. Which of these is not a keyword in C?
- A)
continue - B)
default - C)
string - D)
goto - Answer: C)
string
9. What does the sizeof()
function return in C?
- A) The size of the pointer
- B) The size of the data type
- C) The size of the memory
- D) The size of the variable
- **Answer**
:B) The size of the data type
10. How would you define a constant in C?
- A) `#define PI 3.14`- B) `int PI = 3.14`- C) `const PI = 3.14`- D) `PI = 3.14`- **Answer**: A) `#define PI 3.14`
11. After the following code is executed, what will be the value of x?
int x = 10;x += 5;```- A) 5- B) 10- C) 15- D) 20- **Answer**: C) 15
12. Which loop in C will always execute at least once?
- A) `for`- B) `while`- C) `do-while`- D) `if`- **Answer**: C) `do-while`
13. What is the correct way to declare an array of 10 integers in C?
- A) `int arr[10];`- B) `int arr[10] = {0};`- C) `int arr[];`- D) `int arr(10);`- **Answer**: A) `int arr[10];`
14. What does this code print?
int x = 4, y = 3;printf("%d", x > y ? x : y);```- A) 4- B) 3- C) 1- D) 0- **Answer**: A) 4
15. How would you read a string in C?
- A) `scanf("%s", &str);`- B) `scanf("%s", str);`- C) `scanf("%c", &str);`- D) `scanf("%d", str);`- **Answer**: B) `scanf("%s", str);`
16. Which function(s) are used to allocate memory in C?
- A) `malloc()`- B) `calloc()`- C) `realloc()`- D) All of the above- **Answer**: D) All of the above
17. What will the following code print?
printf("%d", 5 > 2 && 3 < 4);```- A) 1- B) 0- C) -1- D) Undefined- **Answer**: A) 1
18. Which operator is used to get a variable's address in C?
- A) `*`- B) `&`- C) `->`- D) `[]`- **Answer**: B) `&`
19. What does the following code output?
int x = 3;printf("%d", ++x);```- A) 3- B) 4- C) 2- D) Undefined- **Answer**: B) 4
20. Which of these is not a looping structure in C?
- A) `for`- B) `while`- C) `repeat`- D) `do-while`- **Answer**: C) `repeat`
21. What is the default value of a static variable in C?
- A) 0- B) 1- C) Garbage value- D) Undefined- **Answer**: A) 0
22. What will the following code produce?
int x = 10, y = 5;printf("%d", x/y);```- A) 2- B) 2.0- C) 5- D) 5.0- **Answer**: A) 2
23. How do you correctly declare a function in C?
- A) `int function(int a, int b);`- B) `function int(int a, int b);`- C) `int function(a, b);`- D) `function(int a, int b);`- **Answer**: A) `int function(int a, int b);`
24. What’s the correct syntax for defining a macro in C?
- A) `#macro PI 3.14`- B) `#define PI 3.14`- C) `#def PI 3.14`- D) `#macrodef PI 3.14`- **Answer**: B) `#define PI 3.14`
25. What will this code print?
int arr[] = {1, 2, 3, 4, 5};printf("%d", arr[3]);```- A) 1- B) 2- C) 3- D) 4- **Answer**: D) 4
26. Which function do you use to compare two strings in C?
- A) `strcopy()`- B) `strcmp()`- C) `strcat()`- D) `strcompare()`- **Answer**: B) `strcmp()`
27. Which of these is the correct way to declare a variable in C?
- A) `int var;`- B) `int var, var2;`- C) `int var = 0;`- D) All of the above- **Answer**: D) All of the above
28. What does the following code print?
int x = 0;if (x) printf("True");else printf("False");```- A) True- B) False- C) Compilation Error- D) Undefined- **Answer**: B) False
29. What does the continue
statement do in a loop?
- A) It stops the loop.- B) It skips the current iteration and continues with the next one.- C) It breaks out of the loop.- D) It restarts the loop from the beginning.- **Answer**: B) It skips
30. What is the output of the following code?
int arr[] = {10, 20, 30};printf("%d", arr[1]);```- A) 10- B) 20- C) 30- D) Undefined- **Answer**: B) 20
31. Which of the following correctly declares a multidimensional array in
C?
- A) `int arr[3][3];`- B) `int arr(3,3);`- C) `int arr[3,3];`- D) `int arr[3][3] = {0};`- **Answer**: A) `int arr[3][3];`
32. What will the following code print?
int a = 5;int b = 10;printf("%d", a > b);```- A) 0- B) 1- C) 5- D) 10- **Answer**: A) 0
33. Which keyword is used to prevent a variable from being modified?
- A) `static`- B) `const`- C) `volatile`- D) `register`- **Answer**: B) `const`
34. What is the output of this code?
int x = 5, y = 2;printf("%d", x % y);```- A) 2- B) 1- C) 0- D) 3- **Answer**: B) 1
35. What does the break
statement do in a loop?
- A) It terminates the loop immediately.- B) It skips to the next iteration.- C) It pauses the loop temporarily.- D) It continues the loop.- **Answer**: A) It terminates the loop immediately.
36. Which function is used to find the length of a string in C?
- A) `strlen()`- B) `strlength()`- C) `length()`- D) `size()`- **Answer**: A) `strlen()`
37. What is the output of the following code?
int x = 2;printf("%d", x << 1);```- A) 1- B) 2- C) 4- D) 8- **Answer**: C) 4
38. What will be the result of this code?
int x = 10;int y = x++;printf("%d %d", x, y);```- A) 10 10- B) 10 11- C) 11 10- D) 11 11- **Answer**: C) 11 10
39. Which of the following is used to denote the end of a string in C?
- A) `\0`- B) `\n`- C) `\t`- D) `EOF`- **Answer**: A) `\0`
40. Which of these functions can be used to dynamically allocate memory for
an array in C?
- A) `malloc()`- B) `calloc()`- C) `realloc()`- D) All of the above- **Answer**: D) All of the above
41. What is the output of the following code?
int x = 10;int y = 5;printf("%d", x | y);```- A) 10- B) 15- C) 5- D) 0- **Answer**: B) 15
42. Which operator is used to access members of a structure through a
pointer?
- A) `.`- B) `*`- C) `->`- D) `&`- **Answer**: C) `->`
43. What will the following code print?
int x = 5, y = 10;printf("%d", x > y ? x : y);```- A) 5- B) 10- C) 0- D) Undefined- **Answer**: B) 10
44. What is the purpose of the typedef keyword in C?
- A) It defines a new data type.- B) It renames an existing data type.- C) It declares a function.- D) It initializes a variable.- **Answer**: B) It renames an existing data type.
45. Which of the following correctly declares a function pointer in C?
- A) `int (*fptr)(int, int);`- B) `int *fptr(int, int);`- C) `int fptr*(int, int);`- D) `int fptr(int, int);`- **Answer**: A) `int (*fptr)(int, int);`
46. What is the output of the following code?
int arr[] = {10, 20, 30, 40, 50};printf("%d", *(arr + 3));```- A) 10- B) 20- C) 30- D) 40- **Answer**: D) 40
47. Which of these is used to read a single character in C?
- A) `scanf()`- B) `gets()`- C) `fgetc()`- D) `getchar()`- **Answer**: D) `getchar()`
48. How do you check for equality between two strings in C?
- A) `strcomp()`- B) `strcmp()`- C) `strcopy()`- D) `strequal()`- **Answer**: B) `strcmp()`
49. What is the output of this code?
int arr[5] = {0};printf("%d", arr[4]);```- A) 0- B) 5- C) Garbage value- D) Undefined- **Answer**: A) 0
50. Which of the following will correctly free dynamically allocated
memory?
- A) `delete(ptr);`- B) `free(ptr);`- C) `remove(ptr);`- D) `deallocate(ptr);`- **Answer**: B) `free(ptr);`
***
See You Again ***
Share,
Comment, Like
=====================
C Language:
C for the
beginner 's by Md Farrukh Asif
Operators
in C by Md. Farrukh Asif
C's
Control Flow by Md. Farrukh Asif
String handling in C by Md Farrukh Asif
The
Function of C Language by Md. Farrukh Asif
File
Handling With Various Statements/Syntaxes In Programming And Their Output In C
Language.
C
For Beginner's Programming With Output. Course Code – 106 [‘C’]) TMBU,BGP
Bca
Solved Examination Questions With Answers Course Code – 106 [‘C’]) Tmbu,Bgp
Top Programming on Structure, Enumeration (enum), and
their output in C Language by Md Farrukh Asif
The Void Function, Older, Modern, Prototype and Multi file functions by
Farrukh
No comments:
Post a Comment