C Programming — Basics & Syntax
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 100 questions in Basics & Syntax
Consider the following declaration:
int (*func_ptr)(int, int, int);
Which of the following function signatures can be correctly assigned to func_ptr?
A int add(int x, int y, int z) { return x+y+z; }
B int add(int x, int y) { return x+y; }
C void add(int x, int y, int z) { }
D float add(int x, int y, int z) { return x+y+z; }
Correct Answer:  A. int add(int x, int y, int z) { return x+y+z; }
EXPLANATION

func_ptr must point to a function that takes exactly 3 int parameters and returns int. Only option A matches this signature exactly.

Take Test
Q.2 Medium Basics & Syntax
What is the output of this code?
#include
int main() {
int a = 5, b = 10;
a = a ^ b;
b = a ^ b;
a = a ^ b;
printf("%d %d", a, b);
return 0;
}
A 5 10
B 10 5
C 0 0
D 10 10
Correct Answer:  B. 10 5
EXPLANATION

This is a classic XOR swap algorithm. After three XOR operations, a and b exchange their values. Result: a=10, b=5.

Take Test
Q.3 Medium Basics & Syntax
What will be printed by the following code?
#include
int main() {
int arr[5] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d %d", *(p+2), arr[2]);
return 0;
}
A 3 3
B 2 4
C 4 3
D 3 4
Correct Answer:  A. 3 3
EXPLANATION

*(p+2) accesses the element at index 2 (value 3), and arr[2] also accesses index 2 (value 3). Both print 3.

Take Test
Q.4 Medium Basics & Syntax
Consider the following code:
int x = 5;
int *ptr = &x;
int **pptr = &ptr;
printf("%d", **pptr);
What is the output?
A 5
B Address of x
C Address of ptr
D Compilation Error
Correct Answer:  A. 5
EXPLANATION

pptr is a pointer to pointer. **pptr dereferences twice: first to get ptr, then to get x's value which is 5.

Take Test
Which of the following is NOT a valid variable name in C?
A _var123
B 123var
C var_123
D __var
Correct Answer:  B. 123var
EXPLANATION

Variable names cannot start with a digit. They must start with a letter or underscore. Option B violates this rule.

Take Test
Advertisement
What is the output of the following C program?
#include
int main() {
char str[] = "GATE";
printf("%d", sizeof(str));
return 0;
}
A 4
B 5
C 6
D Compilation Error
Correct Answer:  B. 5
EXPLANATION

sizeof(str) includes the null terminator. The string "GATE" has 4 characters plus 1 null terminator = 5 bytes.

Take Test
Which of the following correctly uses memcpy()?
A memcpy(dest, src, strlen(src));
B memcpy(dest, src, sizeof(src));
C memcpy(&dest, &src, count);
D memcpy(dest, src, count);
Correct Answer:  D. memcpy(dest, src, count);
EXPLANATION

memcpy(dest, src, count) copies 'count' bytes from src to dest. strlen() and sizeof() may not give correct results for all data types.

Take Test
What is the output of: float x = 5/2; printf("%f", x);
A 2.5
B 2.0
C 2.500000
D Error
Correct Answer:  B. 2.0
EXPLANATION

5/2 is integer division (not float division), so result is 2 (integer), then converted to 2.0 (float).

Take Test
Which of the following about function pointers in C is correct?
A int *func();
B int (*func)();
C int func*();
D int *func*();
Correct Answer:  B. int (*func)();
EXPLANATION

int (*func)(); declares a pointer to a function that returns int. Option A declares a function returning pointer to int.

Take Test
Q.10 Hard Basics & Syntax
What will be the output of: int a = 1; int b = 2; a = a + b; b = a - b; a = a - b; printf("%d %d", a, b);
A 1 2
B 2 1
C 3 1
D 1 3
Correct Answer:  B. 2 1
EXPLANATION

Initial: a=1, b=2. After step 1: a=3, b=2. After step 2: a=3, b=1. After step 3: a=2, b=1. Output is '2 1'.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips