Beginner C test (Beginner)
25 questions · 30 minutes · Free
Syntax, pointers, arrays and functions.
What it covers
- Data types and operators
- Pointers basics
- Arrays and strings
- Functions
- Control flow
Interview format
- Questions: 25 questions — 15 multiple choice, 8 multi-answer, 2 predict-the-output
- Time: 30 minutes, timed from the first question
- Difficulty: Beginner
- Skill area: Backend
- Price: Free
Earn a certificate
The Beginner C test is one of the 6 tests of the Automotive Embedded Engineer learning path. Pass it and the other 5 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.
Sample questions
5 sample questions from the Beginner C test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
Consider the following function in C: int example() { return 5; } Which of the following statements is true about this function?
- The function does not return a value.
- The function returns the value 5.0.
- The function returns the value 5.
- The function returns the value '5'.
Answer: C. The function returns the value 5.
In C, the return statement is used to return a value from a function. If a function is declared to return an integer (e.g., int function()), it must return an integer value. In this case, the function returns 5, which is an integer, making the statement correct.
What is the result of the following code snippet: printf("%zu", sizeof("hi")); ?
- 4
- 3
- 5
- 2
Answer: A. 4
In C, a string literal like "hi" needs 3 bytes because it includes the two characters 'h' and 'i' plus the terminating null character '\0'. The sizeof operator returns the total size of the array, including the null terminator, which is why the result is 3 in this case.
What is the most likely cause of a bug in the following code snippet that involves a pointer to a structure? struct Data { int value; }; struct Data *ptr; ptr->value = 10;
- The structure is being modified within a function that does not return the updated value.
- The pointer to the structure is not initialized before use, leading to undefined behavior.
- The pointer to the structure is being used incorrectly in an arithmetic operation.
- The structure is not properly declared with the correct data types.
Answer: B. The pointer to the structure is not initialized before use, leading to undefined behavior.
The pointer to the structure is not initialized before use, leading to undefined behavior. In C, when a pointer is declared but not initialized, it contains a garbage value, and dereferencing it can lead to unpredictable results, such as program crashes or incorrect data modification. To fix this, the pointer should be initialized to point to a valid structure instance.
Which of the following statements is true about function overloading in C?
- C supports function overloading using different parameter names
- C supports function overloading using different return types
- C does not support function overloading
- C supports function overloading using type qualifiers
Answer: C. C does not support function overloading
In C, function overloading is not supported. The language does not allow multiple functions with the same name but different parameter lists. This feature is available in languages like C++ but not in C.
What happens if you attempt to dereference a null pointer in a C program?
- Dereferencing a null pointer is allowed in C but may return a default value of 0.
- Dereferencing a null pointer is safe and commonly used in C programs.
- A null pointer can be safely dereferenced as it points to a reserved memory location.
- It is not possible to dereference a null pointer because it does not point to a valid memory address.
Answer: D. It is not possible to dereference a null pointer because it does not point to a valid memory address.
A null pointer does not point to any memory address, so attempting to dereference it would result in undefined behavior or a runtime error. This is why it is crucial to check if a pointer is null before dereferencing it in a project.
Frequently asked questions
- How many questions are in the Beginner C test?
- 25 questions (15 multiple choice, 8 multi-answer, 2 predict-the-output), with 30 minutes to answer them.
- What does the Beginner C test cover?
- Data types and operators, Pointers basics, Arrays and strings, Functions, Control flow.
- Is the Beginner C test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Beginner C test?
- Beginner, in Backend.