C Language MCQs and Answers with Explanation | C Programming Language Quiz

C language MCQ's
Join Telegram Join Telegram
Join Whatsapp Groups Join Whatsapp

C Language MCQs and Answers with Explanation: Want to test your expertise in the C Language and are you searching for a C online quiz/ C Language multiple choice questions? Then this article on C Programming Language MCQs will be a great help to you. C Language is a high-level programming language that was developed by Dennis Ritchie in 1972. It is a widely used language for developing system software, application software, and embedded systems. The C Language is known for its speed, simplicity, and flexibility. It provides low-level memory access and supports modular programming, making it a popular choice for writing operating systems and device drivers. To help beginners and professionals alike, C Language MCQ questions and answers are available in this article. This C Programming Language Quiz not only helps beginners understand the C Language concepts better but also enables professionals to test their expertise in it.

C Language MCQ Questions and Answers

These Top 59 C Language MCQs with answers cover a wide range of topics, from the basics of C Language to advanced concepts, helping individuals test their knowledge and skills in C programming. Here, we provide a set of C Language multiple choice questions to help individuals prepare for interviews and exams or simply to enhance their knowledge of C programming. Now, without any delay, dive into these C Programming MCQ Questions and Answers and test your knowledge.

C Language Multiple Choice Questions

Name C Language
Exam Type MCQ (Multiple Choice Questions)
Category Technical Quiz
Mode of Quiz Online

Top 59 C Programming Language MCQs and Answers | C Programming Language Quiz

1. Which of the following is a valid identifier in C Language?

A) myVariable
B) 1stNumber
C) my-variable
D) _underscore

Answer: A

Explanation: In C Language, an identifier can only begin with a letter or an underscore. It cannot begin with a number or a special character like hyphen (-).

2. Which keyword is used to define a function in C Language?

A) function
B) define
C) main
D) void

Answer: D

Explanation: The void keyword is used to define a function in C Language. It indicates that the function does not return a value.

3. Which operator is used to access the value stored in a variable pointed to by a pointer in C Language?

A) *
B) &
C) $
D) %

Answer: A

Explanation: The * operator is used to access the value stored in a variable pointed to by a pointer in C Language. It is called the dereference operator.

4. Which of the following is not a valid data type in C Language?

A) char
B) float
C) double
D) string

Answer: D

Explanation: String is not a valid data type in C Language. It is a collection of characters and can be represented using character arrays.

5. What is the output of the following code?

int main() {
int x = 5;
printf(“%d”, x++);
return 0;
}

A) 5
B) 6
C) 4
D) None of the above

Answer: A

Explanation: The value of x is first printed using the printf function and then incremented using the ++ operator. Therefore, the output is 5.

6. Which of the following is a valid way to declare an array in C Language?

A) int arr[5];
B) arr[5];
C) int arr[];
D) All of the above

Answer: A

Explanation: The correct way to declare an array in C Language is to specify the data type and the size of the array, as shown in option A.

7. What is the output of the following code?
int main() {
printf(“%d”, sizeof(int));
return 0;
}

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

Answer: C

Explanation: The sizeof operator returns the size of the data type in bytes. The size of an integer in C Language is 4 bytes on most modern computers, so the output is 4.

8. Which of the following is not a valid way to define a constant in C Language?

A) #define PI 3.14
B) const float PI = 3.14;
C) const PI = 3.14;
D) enum { PI = 3.14 };

Answer: C

Explanation: The correct way to define a constant in C Language using the const keyword is to specify the data type, as shown in option B. Option C is missing the data type.

9. What is the output of the following code?

int main() {
int i = 0;
for (i = 0; i < 3; i++) {
printf(“%d “, i);
}
return 0;
}

A) 0 1 2
B) 1 2 3
C) 0 1 2 3
D) None of the above

Answer: A

Explanation: The for loop in the code runs three times, with i starting at 0 and incrementing by 1 each time. The printf function inside the loop prints the value of i each time it runs, so the output is 0 1 2.

10. Which of the following is not a valid way to declare a pointer in C Language?

A) int ptr;
B) int ptr;
C) int * ptr;
D) intptr;

Answer: D

Explanation: Option D is not a valid way to declare a pointer in C Language. The correct syntax is to use the * operator after the data type, as shown in options A, B, and C.

11. What is the output of the following code?

int main() {
int arr[] = {1, 2, 3, 4, 5};
printf(“%d”, *arr);
return 0;
}

A) 1
B) 2
C) 3
D) 4

Answer: A

Explanation: The * operator is used to access the value stored in the first element of the array arr. Therefore, the output is 1.

12. Which of the following is not a valid arithmetic operator in C Language?

A) +
B) –
C) *
D) /

Answer: E

Explanation: There are only four arithmetic operators in C Language, as listed in options A-D. Option E is not a valid operator.

13. What is the output of the following code?

int main() {
int x = 10, y = 5;
printf(“%d”, x > y ? x : y);
return 0;
}

A) 5
B) 10
C) x
D) y

Answer: B

Explanation: The code uses the ternary operator to compare the values of x and y. Since x is greater than y, the ternary operator returns x, which is printed by the printf function.

14. Which of the following is not a valid way to open a file in C Language?

A) fopen(“file.txt”, “r”);
B) fopen(“file.txt”, “w”);
C) fopen(“file.txt”, “a”);
D) open(“file.txt”, “r”);

Answer: D

Explanation: The open function is not a valid way to open a file in C Language. The correct function to use is fopen, as shown in options A-C.

15. What is the output of the following code?

int main() {
int x = 5, y = 10;
if (x == 5 && y == 10) {
printf(“True”);
} else {
printf(“False”);
}
return 0;
}

A) True
B) False
C) Neither True nor False
D) Compilation Error

Answer: A

Explanation: The code uses the && operator to check if both x and y are equal to certain values. Since both conditions are true, the code inside the if statement is executed, and the output is True.

16. Which of the following is a valid way to allocate memory dynamically in C Language?

A) int *ptr = malloc(10);
B) int *ptr = new int[10];
C) int *ptr = calloc(10, sizeof(int));
D) All of the above

Answer: D

Explanation: All three options are valid ways to allocate memory dynamically in C Language. Option A uses the malloc function, option B uses the new operator (which is used in C++ as well), and option C uses the calloc function.

17. What is the output of the following code?

int main() {
int i = 0;
while (i < 3) {
printf(“%d “, i);
i++;
}
return 0;
}

A) 0 1 2
B) 1 2 3
C) 0 1 2 3
D) 1 1 1

Answer: A

Explanation: The code uses a while loop to print the value of the variable i, which is incremented by 1 in each iteration. The loop continues as long as i is less than 3, so the output is 0 1 2.

18. Which of the following is not a valid way to declare a structure in C Language?

A) struct person {
char name[20];
int age;
};
B) typedef struct {
char name[20];
int age;
} person;
C) typedef struct person {
char name[20];
int age;
} person_t;
D) struct {
char name[20];
int age;
} person;

Answer: D

Explanation: Option D is not a valid way to declare a structure in C Language. The correct syntax is to use either the struct keyword followed by a tag name (as in option A and C) or to use the typedef keyword to create a new type name (as in option B).

19. Which of the following is not a valid way to declare a function in C Language?

A) int func();
B) int func(int x);
C) int func(int x, int y);
D) void func(int x, int y) {};

Answer: D

Explanation: Option D is not a valid way to declare a function in C Language. The correct syntax is to use parentheses after the function name to specify the arguments (as in options A-C).

20. What is the output of the following code?

int main() {
int i, sum = 0;
for (i = 1; i <= 5; i++)
{
if (i % 2 == 0) {
continue;
}
sum += i;
}
printf(“%d”, sum);
return 0;
}

A) 9
B) 6
C) 3
D) 15

Answer: C

Explanation: The code uses a for loop to iterate over the values from 1 to 5. If the current value of i is even, the continue statement is used to skip to the next iteration. Otherwise, the current value of i is added to the variable sum. Since the values of i that are added to sum are 1 and 3, the final value of sum is 4.

21. Which of the following is not a valid way to declare a variable in C Language?

A) int x;
B) float y = 3.14;
C) char z[20] = “hello”;
D) bool b = true;

Answer: D

Explanation: Option D is not a valid way to declare a variable in C Language. C Language does not have a built-in bool data type, instead it uses integers to represent boolean values (0 for false, 1 for true).

22. What is the output of the following code?

int main() {
int i;
for (i = 0; i < 3; i++) {
if (i == 1) {
break;
}
printf(“%d “, i);
}
return 0;
}

A) 0
B) 1
C) 0 1
D) 0 2

Answer: A

Explanation: The code uses a for loop to iterate over the values from 0 to 2. If the current value of i is equal to 1, the break statement is used to exit the loop. Otherwise, the current value of i is printed using printf. Since the loop is exited when i is equal to 1, only the value 0 is printed.

23. What is the output of the following code?

int main() {
int a = 5, b = 2;
printf(“%d”, a % b);
return 0;
}

A) 1
B) 2
C) 2.5
D) 5

Answer: A

Explanation: The % operator is used to calculate the remainder of integer division. In this case, 5 divided by 2 has a remainder of 1, so the output is 1.

24. What is the output of the following code?

int main() {
int a = 5, b = 2;
printf(“%d”, a / b);
return 0;
}

A) 2.5
B) 2
C) 5
D) 2.0

Answer: B

Explanation: The / operator is used to perform integer division. In this case, 5 divided by 2 is 2 with a remainder of 1, but since this is integer division, the remainder is discarded and the output is 2.

25. What is the output of the following code?

int main() {
int i = 0;
while (i < 3) {
printf(“%d “,

A) 0 1 2
B) 1 2 3
C) 0 1 2 3
D) infinite loop

Answer: A

Explanation: The code uses a while loop to print the values of i from 0 to 2. The loop continues as long as i is less than 3. In each iteration of the loop, the value of i is printed using printf, and then incremented by 1 using the ++ operator. Since the loop stops when i becomes 3, the output is 0 1 2.

26. What is the output of the following code?

int main() {
int x = 5, y = 2, z;
z = x > y ? x – y : y – x;
printf(“%d”, z);
return 0;
}

A) 3
B) 2
C) 5
D) 7

Answer: A

Explanation: The code uses the ternary operator to calculate the absolute difference between x and y. The expression x > y ? x – y : y – x is equivalent to if (x > y) { z = x – y; } else { z = y – x; }. Since x is greater than y, the value of z is 5 – 2 = 3.

27. What is the output of the following code?

int main() {
int a = 5, b = 2;
printf(“%f”, (float)a / b);
return 0;
}

A) 2.5
B) 2
C) 2.0
D) 5

Answer: A

Explanation: The (float) cast operator is used to convert the value of a to a floating-point number before performing the division. In this case, 5 divided by 2 is 2.5, so the output is 2.5.

28. What is the output of the following code?

int main() {
int a = 5, b = 2;
printf(“%d”, a * b++);
return 0;
}

A) 10
B) 12
C) 14
D) 15

Answer: A

Explanation: The * operator has higher precedence than the ++ operator, so the multiplication is performed before the increment. The value of b is then incremented after the multiplication. Since 5 times 2 is 10, the output is 10.

29. What is the output of the following code?

int main() {
int a = 5, b = 2;
printf(“%d”, ++a * b);
return 0;
}

A) 12
B) 14
C) 15
D) 20

Answer: D

Explanation: The ++ operator has higher precedence than the * operator, so the increment is performed before the multiplication. The value of a is then used in the multiplication, and since its value was incremented to 6, the output is 6 times 2, which is 12.

30. What is the output of the following code?

int main() {
int i = 1;
do {
printf(“%d “, i++);
} while (i <= 3);
return 0;
}

A) 1 2 3
B) 1 3
C) 2 3
D) 2

Answer: A

Explanation: The code uses a do-while loop to print the values of i from 1 to 3. The loop continues as long as i is less than or equal to 3. In each iteration of the loop, the value of i is printed using printf, and then incremented by 1 using the ++ operator. Since the loop stops when i becomes 4, the output is 1 2 3.

31. What is the output of the following code?

int main() {
int a[] = {1, 2, 3, 4, 5};
printf(“%d”, a[3]);
return 0;
}

A) 1
B) 3
C) 4
D) 5

Answer: C

Explanation: The code defines an integer array a with 5 elements, and initializes it with the values 1, 2, 3, 4, and 5. The fourth element of the array is accessed using the subscript operator [], and since the array is 0-indexed, the fourth element has index 3. The value stored in this element is 4, so the output is 4.

32. What is the output of the following code?

int main() {
int a[] = {1, 2, 3, 4, 5};
printf(“%d”, *(a + 3));
return 0;
}

A) 1
B) 3
C) 4
D) 5

Answer: C

Explanation: The code defines an integer array a with 5 elements, and initializes it with the values 1, 2, 3, 4, and 5. The fourth element of the array can be accessed using the pointer arithmetic expression *(a + 3), which is equivalent to a[3]. The value stored in this element is 4, so the output is 4.

33. What is the output of the following code?

int main() {
int a[] = {1, 2, 3, 4, 5};
printf(“%d”, *a);
return 0;
}

A) 1
B) 3
C) 4
D) 5

Answer: A

Explanation: The code defines an integer array a with 5 elements, and initializes it with the values 1, 2, 3, 4, and 5. The first element of the array can be accessed using the pointer arithmetic expression *a, which is equivalent to a[0]. The value stored in this element is 1, so the output is 1.

34. What is the output of the following code?

int main() {
int a[] = {1, 2, 3, 4, 5};
printf(“%d”, *(a + 2));
return 0;
}

A) 1
B) 3
C) 4
D) 5

Answer: B

Explanation: The code defines an integer array a with 5 elements, and initializes it with the values 1, 2, 3, 4, and 5. The third element of the array can be accessed using the pointer arithmetic expression *(a + 2), which is equivalent to a[2]. The value stored in this element is 3, so the output is 3.

35. What is the output of the following code?

int main() {
int a[] = {1, 2, 3, 4, 5};
printf(“%d”, a);
return 0;
}

A) 1
B) 3
C) 4
D) the address of the first element of the array

Answer: D

Explanation: The code defines an integer array a with 5 elements, and initializes it with the values 1, 2, 3, 4, and 5. The printf statement prints the value of the variable a, which is the address of the first element of the array. Therefore, the output is the address of the first element of the array.

36. What is the output of the following code?

int main() {
int a[] = {1, 2, 3, 4, 5};
printf(“%d”, &a[1]);
return 0;
}

A) 1
B) 3
C) 4
D) the address of the second element of the array

Answer: D

Explanation: The code defines an integer array a with 5 elements, and initializes it with the values 1, 2, 3, 4, and 5. The printf statement prints the address of the second element of the array, which is obtained using the & operator and the subscript operator []. Therefore, the output is the address of the second element of the array.

37. What is the output of the following code?

int main() {
int a[] = {1, 2, 3, 4, 5};
printf(“%d”, sizeof(a));
return 0;
}

A) 1
B) 3
C) 4
D) the size of the array in bytes

Answer: D

Explanation: The code defines an integer array a with 5 elements, and initializes it with the values 1, 2, 3, 4, and 5. The sizeof operator returns the size of the array in bytes, which is equal to the number of elements in the array times the size of each element. Since each element of the array is an integer, which typically takes up 4 bytes of memory, the size of the array is 5 * 4 = 20 bytes. Therefore, the output is 20.

38. What is the output of the following code?

int main() {
int a[] = {1, 2, 3, 4, 5};
printf(“%d”, sizeof(a) / sizeof(int));
return 0;
}

A) 1
B) 3
C) 4
D) the number of elements in the array

Answer: D

Explanation: The code defines an integer array a with 5 elements, and initializes it with the values 1, 2, 3, 4, and 5. The sizeof operator returns the size of the array in bytes, and the sizeof(int) operator returns the size of an integer in bytes. Therefore, the expression sizeof(a) / sizeof(int) gives the number of elements in the array. Since each element of the array is an integer, and the size of an integer is typically 4 bytes, the output is 5 / 1 = 5.

39. What is the output of the following code?

int main() {css
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int *p = a[0];
printf(“%d”, *(p + 4));
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: C

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is initialized to point to the first element of the array, which is a[0][0]. The pointer arithmetic expression *(p + 4) corresponds to the element a[1][1], which has the value 5. Therefore, the output is 5.

40. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int **p = a;
printf(“%d”, **p + 1);
return 0;
}

A) 1
B) 2
C) 4
D) 5

Answer: B

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to a pointer to an integer, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression **p corresponds to the value of the first element of the array, which is 1. Adding 1 to this value gives 2. Therefore, the output is 2.

41. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int **p = a;
printf(“%d”, *(*p + 1));
return 0;
}

A) 1
B) 2
C) 4
D) 5

Answer: B

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to a pointer to an integer, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression *(*p + 1) corresponds to the value of the second element of the first row of the array, which is 2. Therefore, the output is 2.

42. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (*p)[3] = a;
printf(“%d”, ((p + 1) + 2));
return 0

A) 2
B) 5
C) 6
D) 8

Answer: C

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression ((p + 1) + 2) corresponds to the value of the third element of the second row of the array, which is 6. Therefore, the output is 6.

43. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (p)[3] = a;
printf(“%d”, ((p + 1))[2]);
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: C

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression (*(p + 1))[2] corresponds to the value of the third element of the second row of the array, which is 6. Therefore, the output is 6.

44. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (p)[3] = a;
printf(“%d”, ((++p))[2]);
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: D

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression (*(++p))[2] corresponds to the value of the third element of the second row of the array, which is 8. Therefore, the output is 8.

45. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (p)[3] = a;
printf(“%d”, (++p)[2]);
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: D

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression (*++p)[2] corresponds to the value of the third element of the second row of the array, which is 8. Therefore, the output is 8.

46. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (*p)[3] = a;
printf(“%d”, ((p + 2) – 1));
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: B

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression ((p + 2) – 1) corresponds to the value of the second element of the third row of the array, which is 5. Therefore, the output is 5.

47. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (*p)[3] = a;
printf(“%d”, ((p + 1) + 1));
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: C

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression ((p + 1) + 1) corresponds to the value of the second element of the second row of the array, which is 5. Therefore, the output is 5.

48. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (*p)[3] = a;
printf(“%d”, *(p[1] + 2));
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: C

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression *(p[1] + 2) corresponds to the value of the third element of the second row of the array, which is 6. Therefore, the output is 6.

49. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (*p)[3] = a;
printf(“%d”, (*p)[1]);
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: A

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression (*p)[1] corresponds to the value of the second element of the first row of the array, which is 2. Therefore, the output is 2.

50. What is the output of the following code?

int main() {
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int (*p)[3] = a;
printf(“%d”, *(p[2] + 1));
return 0;
}

A) 2
B) 5
C) 6
D) 8

Answer: D

Explanation: The code defines a 2-dimensional integer array a with 3 rows and 3 columns, and initializes it with the values 1, 2, 3, 4, 5, 6, 7, 8, and 9. The pointer variable p is declared as a pointer to an array of 3 integers, and is initialized to point to the first row of the array, which is equivalent to the address of the first element of the array, which is a[0][0]. The expression *(p[2] + 1) corresponds to the value of the second element of the third row of the array, which is 8. Therefore, the output is 8.

51. What is the output of the following code?

int main() {
int a[] = {10, 20, 30, 40, 50};
int *p = a;
printf(“%d”, *(p + 2));
return 0;
}

A) 10

B) 20

C) 30

D) 40

Answer: C

Explanation: The code declares an integer array a with 5 elements and initializes it with the values 10, 20, 30, 40, and 50. The pointer variable p is declared and initialized to point to the first element of the array, which is equivalent to the address of a[0]. The expression *(p + 2) corresponds to the value of the third element of the array, which is 30. Therefore, the output of this code is 30.

52. What is the output of the following code?

int main() {
int a[] = {10, 20, 30, 40, 50};
int *p = a + 2;
printf(“%d”, *p);
return 0;
}

A) 10
B) 20
C) 30
D) 40

Answer: C

Explanation: The code declares an integer array a with 5 elements and initializes it with the values 10, 20, 30, 40, and 50. The pointer variable p is declared and initialized to point to the third element of the array, which is equivalent to the address of a[2]. The expression *p corresponds to the value of the third element of the array, which is 30. Therefore, the output of this code is 30.

53. What is the output of the following code?

int main() {
int a[] = {10, 20, 30, 40, 50};
int *p = a;
printf(“%d”, ++*p);
return 0;
}

A) 10
B) 20
C) 30
D) 11

Answer: D

Explanation: The code declares an integer array a with 5 elements and initializes it with the values 10, 20, 30, 40, and 50. The pointer variable p is declared and initialized to point to the first element of the array, which is equivalent to the address of a[0]. The expression ++*p increments the value of the first element of the array, which becomes 11, and returns the incremented value. Therefore, the output of this code is 11.

54. What is the output of the following code?

int main() {
int a[] = {10, 20, 30, 40, 50};
int *p = a + 2;
printf(“%d”, *(p++));
return 0;
}

A) 20
B) 30
C) 40
D) 50

Answer: B

Explanation: The code declares an integer array a with 5 elements and initializes it with the values 10, 20, 30, 40, and 50. The pointer variable p is declared and initialized to point to the third element of the array, which is equivalent to the address of a[2]. The expression *(p++) corresponds to the value of the third element of the array, which is 30, and then increments the pointer variable p to point to the next element of the array, which is equivalent to the address of a[3]. Therefore, the output of this code is 30.

55. What is the output of the following code?

int main() {
char str[] = “Hello, World!”;
printf(“%c”, str[7]);
return 0;
}

A) H
B) W
C) o
D) l

Answer: B

Explanation: The code declares a character array str with the string “Hello, World!”. The expression str[7] corresponds to the eighth character of the string, which is ‘W’. Therefore, the output of this code is W.

56. What is the output of the following code?

int main() {
char str[] = “Hello, World!”;
char *p = str;
printf(“%c”, *(p + 7));
return 0;
}

A) H
B) W
C) o
D) l

Answer: B

Explanation: The code declares a character array str with the string “Hello, World!”. The pointer variable p is declared and initialized to point to the first character of the string, which is equivalent to the address of str[0]. The expression *(p + 7) corresponds to the eighth character of the string, which is ‘W’. Therefore, the output of this code is W.

57. What is the output of the following code?

int main() {
char str[] = “Hello, World!”;
char *p = str;
printf(“%s”, p + 7);
return 0;
}

A) Hello, World!
B) World!
C) lo, World!
D) o, World!

Answer: B

Explanation: The code declares a character array str with the string “Hello, World!”. The pointer variable p is declared and initialized to point to the first character of the string, which is equivalent to the address of str[0]. The expression p + 7 corresponds to the address of the eighth character of the string, which is equivalent to the address of str[7]. The printf() function with the format specifier “%s” is used to print the string starting from the address pointed to by p + 7, which is “World!”. Therefore, the output of this code is World!.

58. What is the output of the following code?

int main() {
char str[] = “Hello, World!”;
char *p = str;
printf(“%c”, *++p);
return 0;
}

A) H
B) e
C) l
D) o

Answer: B

Explanation: The code declares a character array str with the string “Hello, World!”. The pointer variable p is declared and initialized to point to the first character of the string, which is equivalent to the address of str[0]. The expression *++p increments the pointer variable p to point to the second character of the string, which is equivalent to the address of str[1], and then dereferences the pointer to obtain the value of the second character, which is ‘e’. Therefore, the output of this code is e.

59. What is the output of the following code?

int main() {
int a[] = {10, 20, 30, 40, 50};
int *p = a + 2;
printf(“%d”, *(p – 1));
return 0;
}

A) 10
B) 20
C) 30
D) 40

Answer: B

Explanation: The code declares an integer array a with 5 elements and initializes it with the values 10, 20, 30, 40, and 50. The pointer variable p is declared and initialized to point to the third element of the array, which is equivalent to the address of a[2]. The expression *(p – 1) corresponds to the value of the second element of the array, which is 20. Therefore, the output of this code is 20.

Mastering the C Language through C Programming MCQ questions and answers can help you achieve better results in interviews and exams, and enhance your ability to write efficient and reliable code. Keep following our Freshersnow portal regularly to get more latest technical quizzes to enhance your knowledge.