C Programming Language Certified Associate Practice Test

The C Programming Language Certified Associate (CLA) certification is a recognized credential for aspiring C programmers. It tests proficiency in the foundational aspects of C programming. Here, we have compiled a practice test of 25 multiple-choice questions, complete with answers and explanations, to help you prepare for the exam.

1. Which of the following is a correct comment in C?

A) <!– Comment –>
B) // Comment
C) /* Comment —
D) # Comment

Answer:

B) // Comment

Explanation:

In C, // is used for single-line comments and /* */ is used for multi-line comments.

2. What will be the output of the following code?

printf("%d", sizeof(char));
A) 0
B) 1
C) 2
D) Compiler Error

Answer:

B) 1

Explanation:

The sizeof(char) in C is always 1 byte.

3. Which function is used to read a single character from the console in C?

A) scanf()
B) getchar()
C) gets()
D) readchar()

Answer:

B) getchar()

Explanation:

getchar() is used to read a single character from the standard input (console).

4. What will be the initial value of a local variable in C?

A) 0
B) Null
C) Garbage Value
D) None of the above

Answer:

C) Garbage Value

Explanation:

Local variables in C are not initialized by default. They contain garbage values.

5. Which of the following is the correct way to declare a pointer in C?

A) int *p;
B) int p;
C) int* p;
D) Both A and C

Answer:

D) Both A and C

Explanation:

Both int *p; and int* p; are correct ways to declare a pointer to an integer in C.

6. Which header file should be included to use the malloc() function in C?

A) #include <malloc.h>
B) #include <memory.h>
C) #include <stdlib.h>
D) #include <alloc.h>

Answer:

C) #include <stdlib.h>

Explanation:

The malloc() function is declared in the stdlib.h header file.

7. What is the purpose of the return 0; statement in the main() function in C?

A) It returns the value 0 to the operating system.
B) It returns the value 0 to the main() function.
C) It terminates the program.
D) It is a syntax requirement.

Answer:

A) It returns the value 0 to the operating system.

Explanation:

The return 0; statement in the main() function indicates successful execution and returns the value 0 to the operating system.

8. Which of the following is NOT a logical operator in C?

A) &&
B) ||
C) !
D) &

Answer:

D) &

Explanation:

The & operator is a bitwise AND operator, not a logical operator in C.

9. Which of the following is the correct syntax to open a file in read mode in C?

A) fopen("file.txt", "r");
B) open("file.txt", "r");
C) fopen(file.txt, r);
D) fileopen("file.txt", "r");

Answer:

A) fopen("file.txt", "r");

Explanation:

The fopen() function is used to open a file in different modes, and "r" is the mode specifier for reading.

10. What does the break statement do in a C program?

A) It terminates the loop.
B) It continues with the next iteration of the loop.
C) It breaks the program.
D) It resumes the execution of the loop.

Answer:

A) It terminates the loop.

Explanation:

The break statement in C is used to terminate the loop and transfer execution to the statement immediately following the loop.

11. How many elements does the array int arr[5] have?

A) 0
B) 4
C) 5
D) 6

Answer:

C) 5

Explanation:

The array int arr[5] is declared to have 5 elements.

12. What will be the output of the following code snippet?

int a = 10;
printf("%d %d %d", a, ++a, a++);
A) 10 11 11
B) 11 11 10
C) 12 12 10
D) Compiler Error

Answer:

B) 11 11 10

Explanation:

The printf function evaluates the arguments from right to left, hence a++ is evaluated first, then ++a, and finally a.

13. Which of the following is an unconditional control statement in C?

A) if
B) for
C) goto
D) while

Answer:

C) goto

Explanation:

The goto statement is an unconditional control statement as it does not depend on any condition.

14. Which of the following is NOT a storage class specifier in C?

A) auto
B) register
C) static
D) constant

Answer:

D) constant

Explanation:

constant is not a storage class specifier in C. The storage class specifiers in C are auto, register, static, and extern.

15. What is the purpose of the #define directive in C?

A) To define a function
B) To include a file
C) To define a macro
D) To define a variable

Answer:

C) To define a macro

Explanation:

The #define directive is used to define a macro in C.

16. What will be the output of the following code snippet?

int a = 5, b = 10;
printf("%d", a+++b);
A) 15
B) 16
C) 14
D) Syntax Error

Answer:

A) 15

Explanation:

The expression a+++b is parsed as (a++) + b, so the value of a is incremented after the value 5 is used in the addition.

17. Which of the following functions is used to find the length of a string in C?

A) strlen()
B) strlength()
C) length()
D) size()

Answer:

A) strlen()

Explanation:

The strlen() function is used to find the length of a string in C.

18. What will happen if we try to store the value 1000 in a char data type variable in C?

A) Compile-time Error
B) Run-time Error
C) The value will be truncated
D) The program will crash

Answer:

C) The value will be truncated

Explanation:

char data type in C can only hold values from -128 to 127 (signed) or 0 to 255 (unsigned). Storing a value outside this range will result in truncation.

19. Which of the following is the correct syntax for a function pointer declaration in C?

A) int *func(int, int);
B) int *func(int, int);
C) int (func)(int, int);
D) int func(int, int);

Answer:

C) int (func)(int, int);

Explanation:

The correct syntax for declaring a function pointer in C is return_type (*pointer_name)(parameter_list);.

20. Which of the following statements is true about the sizeof operator in C?

A) It returns the size of a variable in bytes.
B) It returns the size of a data type in bits.
C) It returns the length of an array.
D) It returns the size of a pointer.

Answer:

A) It returns the size of a variable in bytes.

Explanation:

The sizeof operator in C is used to get the size of a variable or data type in bytes.

21. Which of the following operators has the highest precedence in C?

A) ++
B) *
C) +
D) &&

Answer:

A) ++

Explanation:

In C, the ++ (increment) operator has the highest precedence among the options given.

22. What is the default return type of a function in C?

A) void
B) int
C) float
D) double

Answer:

B) int

Explanation:

If the return type of a function is not specified in C, it defaults to int.

23. What is the scope of a static variable defined within a function in C?

A) The function in which it is defined.
B) The file in which it is defined.
C) The block in which it is defined.
D) Throughout the program.

Answer:

A) The function in which it is defined.

Explanation:

A static variable defined within a function in C retains its value between function calls but is only accessible within that function.

24. Which of the following C libraries should be included to use the sqrt() function?

A) #include <math.h>
B) #include <stdlib.h>
C) #include <string.h>
D) #include <stdio.h>

Answer:

A) #include <math.h>

Explanation:

The sqrt() function is declared in the math.h library in C.

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

int a = 10;
int b = a++;
printf("%d %d", a, b);
A) 11 11
B) 10 10
C) 11 10
D) 10 11

Answer:

C) 11 10

Explanation:

The variable b is assigned the value of a before a is incremented. Therefore, b is 10 and a is 11.


This set of practice questions is designed to help you review and reinforce your understanding of foundational C programming concepts. Thoroughly understanding the explanations provided will help you get one step closer to achieving the C Programming Language Certified Associate certification. Happy coding!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top