C Coding Questions: Practice Set 1 for Placement Prep
10 C MCQs covering pointer passing, double pointers, structures, strings, and memory allocation with full explanations and a corrected code trace.
Pointer operations, memory allocation, and structure usage appear in C-language MCQs across TCS NQT, AMCAT, Infosys, and Wipro aptitude rounds. The 10 questions below cover the five areas these tests focus on most. Each question includes the correct answer, the wrong-answer traps, and the concept reasoning behind the choice.
Why These 10 Questions Appear in Placement Tests
C was the dominant teaching language in Indian engineering colleges for over two decades, and campus recruitment tests still weight it heavily. Service-tier companies include 8 to 15 C-language MCQs per aptitude paper. Product-tier interviews often ask candidates to trace or write C code on a whiteboard or in an online IDE.
What the tests are really measuring is not C syntax for its own sake. They measure whether a candidate understands how memory is laid out, how data flows through function calls, and what happens at the boundary between a caller and a callee. A student who has genuinely traced pointer operations handles code-reading MCQs in under 30 seconds. A student who has memorised syntax without understanding memory will stall.
The questions in this set target exactly that. Questions 1, 7, and 10 build from basic pointer passing to double pointers to a live code trace. Questions 2 and 4 cover structures. Questions 3, 5, and 6 cover the standard library. Questions 8 and 9 test fundamental rules about variable names and keywords.
For more on tracing array operations in C, the companion article on inserting and searching elements in arrays covers insertion, deletion, and search with Big-O analysis.
Pointer Passing and Double Pointers
Pointers are the concept that trips up the largest share of test candidates. The confusion usually comes from two sources: conflating the pointer itself with the data it points to, and misreading what ++ does when applied to a double pointer. Questions 1, 7, and 10 below isolate each of these failure modes.
Q1: Can a pointer variable be passed as a function argument?
- Options: changed within function / assigned an integer value / none of these / passed to a function as argument
- Correct answer: passed to a function as argument
- Explanation: A pointer variable can be passed to a function as an argument. The function receives the memory address stored in the pointer and can read or modify the original data at that address through dereferencing with
*. This is one of the most common patterns in C: passing&variableto a function that takes a pointer parameter, so the function can write back a result to the caller.
Q7: What does the declaration int **ptr mean?
- Options: pointer to integer / none of these / pointer to pointer to integer / invalid declaration
- Correct answer: pointer to pointer to integer
- Explanation:
int **ptrdeclaresptras a pointer to a pointer to an integer. The first*meansptris a pointer; the second*means what it points to is itself a pointer, not a raw integer. Dereferencing once (*ptr) gives anint*. Dereferencing twice (**ptr) gives theintvalue. - Where you see this: double pointers appear in functions that need to modify a pointer variable in the caller. Passing
&my_arrayto a function takingint**lets the function reassignmy_arrayto a newly allocated block. - For the full pointer declaration syntax, see the cppreference pointer declaration reference.
Q10: Code trace — what does this program print?
A version of this question circulates widely with a subtle bug: the function body reads ++param instead of ++(*param). These two operations produce completely different results, and the distinction is exactly what the question is designed to test.
++paramincrements the localchar**parameter. Thestringvariable back inmainis unchanged. Output:hello_World.++(*param)increments thechar*thatparampoints to, which isstringinmain. Each call advances the string’s start address by one character.
The corrected version of the code, which produces the stated output of llo_World:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void myfunc(char** param) {
++(*param); /* advance the pointer that param addresses */
}
int main(void) {
char* string = (char*)malloc(64);
strcpy(string, "hello_World");
myfunc(&string); /* string now starts at 'e': "ello_World" */
myfunc(&string); /* string now starts at 'l': "llo_World" */
printf("%s\n", string);
return 0;
}
- Step-by-step trace:
- Before first call:
stringpoints to'h', giving"hello_World" - After first
myfunc(&string):++(*param)runs, advancingstringto'e', giving"ello_World" - After second
myfunc(&string):stringadvances to'l', giving"llo_World"
- Before first call:
- Output:
llo_World - The lesson: in a function taking
char** param, writing++parammoves the localchar**variable with no effect on the caller’s pointer. Writing++(*param)moves the underlyingchar*pointer that the caller owns. The distinction between modifying the pointer and modifying what the pointer holds is the core of this question.
Structures in C: Grouping Different Data Types
C arrays store elements of a single type in contiguous memory. Structures solve a different problem: grouping fields of different types under one name. Both Q2 and Q4 below test whether the student can correctly classify which data containers are heterogeneous (different types) and which are not.
Q2: Which of the following uses a structure?
- Options: linked list / array of structures / all of these / binary tree
- Correct answer: all of these
- Explanation: all three data structures rely on
struct. A linked list node holds a data field and a pointer to the next node. Different types under one struct. An array of structures is a sequence of identical struct instances, each with its own fields. A binary tree node holds a value and two child pointers. Every one of these standard data structures is built onstruct.
Q4: Which of the following is a collection of different data types?
- Options: string / structure / array / files
- Correct answer: structure
- Explanation: an array in C holds elements of the same type throughout. A structure holds fields that can be of any type: an integer, a float, a character array, and a pointer can all coexist in the same struct. Strings in C are simply arrays of
char, not heterogeneous containers. File handles (FILE*) are opaque pointer types, not general-purpose data containers. - Why this matters in tests: placement MCQs frequently pair this question with a code fragment that mixes struct and array syntax. Knowing that
structis the heterogeneous container and array is the homogeneous one answers both the theory question and the code-reading variant.
Strings, Header Files, and Memory Management
Three of the 10 questions target the standard library: the null terminator that ends every string, the header file for mathematical functions, and the correct way to release dynamically allocated memory. These appear in service-tier aptitude tests because they test whether a candidate knows the C runtime well enough to read unfamiliar code.
Q3: What is the null-terminated character in a string array?
- Options: t / 1 / backslash-zero / n
- Correct answer:
\0(the null character, ASCII value 0) - Explanation: in C, a string is a contiguous array of
charvalues with\0as the final element. Every string literal the compiler creates appends\0automatically. Functions in<string.h>and<stdio.h>all depend on finding\0to know where the string ends. Forgetting to null-terminate achararray causes functions likeprintfandstrcpyto read past the end of the buffer, producing undefined behaviour.
Q6: Which header file is used for basic mathematical operations in C?
- Options:
<conio.h>/<stdio.h>/<math.h>/<dos.h> - Correct answer:
<math.h> - Explanation:
<math.h>declares functions includingsqrt(),sin(),cos(),tan(),pow(),log(), andceil(). Including<stdio.h>gives I/O functions (printf,scanf). Including<conio.h>gives console I/O functions from older Turbo C environments, largely absent from modern compilers.<dos.h>was DOS-specific and is not part of the C standard.
Q5: What function should be used to free memory allocated by calloc()?
- Options:
free()/malloc(variable_name, 0)/dealloc()/memalloc(variable_name, 0) - Correct answer:
free() - Explanation: the C standard library
free()function accepts a pointer previously returned bymalloc(),calloc(), orrealloc()and releases the block back to the heap. There is no standarddealloc()ormemalloc()in C. Callingmalloc(ptr, 0)is invalid syntax. After callingfree(ptr), assignptr = NULLimmediately: accessing a freed pointer is undefined behaviour. - The difference between
malloc()andcalloc()is initialisation.malloc()returns a block with uninitialised contents.calloc()zeroes the allocated block before returning. Both are released with the samefree()call.
C Language Ground Rules: Variables and Keywords
Two questions in this set test the rules that govern identifiers and reserved words. They look trivial but catch candidates who have only used online editors where syntax highlighting masks the distinction.
Q8: Which special symbol is allowed in a C variable name?
- Options: the
_character / hyphen / pipe / asterisk - Correct answer: the
_character - Explanation: C variable names may contain letters (
a-z,A-Z), digits (0 to 9, but not as the first character), and underscores. Hyphens, pipes, asterisks, and all other punctuation are not valid. The restriction is not arbitrary: a hyphen parses as subtraction, an asterisk parses as pointer declaration or multiplication, and a pipe parses as bitwise-OR. The compiler would misreadstudent-nameasstudentminusname. - Valid examples:
student_name,_count,total_items. Invalid:student-name,total*count.
Q9: What case are C keywords written in?
- Options: uppercase / none of these / lowercase / camelCase
- Correct answer: lowercase
- Explanation: every reserved word in the C standard is lowercase:
int,return,if,else,for,while,struct,void,char,float,double,switch,case. C is case-sensitive. WritingINTorReturncreates a valid identifier, not a keyword, which the compiler treats as an undeclared variable. Students coming from case-insensitive languages sometimes writeFORorWHILEand are surprised when the compiler rejects the code.
Placement rounds include aptitude reasoning beyond C code. The coding-decoding question guide covers the seven types used in TCS NQT and AMCAT.
The ++param vs ++(*param) distinction in Q10 illustrates the precision placement tests check: did you trace the code, or guess? Pointer reasoning transfers directly to API work. At ₹299, TinkerLLM puts live LLM API calls in your hands, and once the C fundamentals are solid, building against a real endpoint is the natural next step.
Primary sources
Frequently asked questions
Can a pointer variable be passed to a function in C?
Yes. Passing a pointer as a function argument gives the function direct access to the original variable's memory address. The function can then read or modify the original value through dereferencing.
What does int **ptr declare in C?
int **ptr declares ptr as a pointer to a pointer to an integer. Dereferencing once gives an int pointer; dereferencing twice gives the integer value. It is commonly used when a function needs to modify a pointer variable in the caller.
Which header file provides mathematical functions in C?
math.h provides functions including sqrt(), sin(), cos(), pow(), and log(). Link with -lm when compiling on Linux.
What is the null terminator in a C string?
The null terminator (written as backslash-zero in source code) marks the end of every C string. Functions like printf, strlen, and strcpy rely on finding it to determine where the string ends. Forgetting to null-terminate a char array causes buffer overruns.
Which function releases memory allocated by calloc or malloc?
free() is the correct function. Pass the pointer returned by calloc() or malloc() to free(). After calling free(), set the pointer to NULL to prevent use-after-free bugs, which cause undefined behaviour.
Which special symbol is allowed in a C variable name?
Only the underscore is permitted as a special character in a C variable name. Hyphens, asterisks, pipes, and percent signs are not valid. Variable names must start with a letter or underscore, not a digit.
A self-paced playground for building with LLMs.
TinkerLLM is FACE Prep's sister property. A guided environment for shipping real LLM applications, the kind of project that earns a paragraph on your resume, not a line.
Try TinkerLLM (₹299 launch)