Home Subjects C Programming Basics & Syntax

C Programming
Basics & Syntax

C language from basics to advanced placement prep

40 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–20 of 40
Topics in C Programming
Q.11 Medium Basics & Syntax
What will be printed by: int arr[3] = {1, 2, 3}; printf("%d", *(arr + 1));
A 1
B 2
C 3
D Undefined
Correct Answer:  B. 2
EXPLANATION

arr + 1 points to the second element, so *(arr + 1) dereferences it to give 2.

Test
Q.12 Medium Basics & Syntax
Which of the following statements about NULL is correct?
A NULL is a keyword in C
B NULL is typically defined as (void *)0
C NULL and 0 are interchangeable for pointers
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

NULL is a macro (not a keyword) typically defined as (void *)0, and can be used interchangeably with 0 for pointer assignments.

Test
Q.13 Medium Basics & Syntax
In C, what is the difference between #include and #include "stdio.h"?
A They are identical
B searches standard directories; "" searches current directory first
C "" is only for user-defined headers
D is only for system headers
Correct Answer:  B. searches standard directories; "" searches current directory first
EXPLANATION

Angle brackets search standard include directories, while quotes search the current directory first, then standard directories.

Test
Q.14 Medium Basics & Syntax
Which of the following is a correct way to initialize a character array with a string?
A char str[] = "Hello";
B char str[5] = "Hello";
C char *str = "Hello";
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

All three are valid ways to work with strings in C, though they differ in memory allocation and mutability.

Test
Q.15 Medium Basics & Syntax
What will be printed by: printf("%d", sizeof(float));
A 2
B 4
C 8
D Compiler dependent
Correct Answer:  B. 4
EXPLANATION

On most systems, sizeof(float) is 4 bytes. Though technically implementation-defined, 4 bytes is standard.

Test
Q.16 Medium Basics & Syntax
What is the correct syntax to define a macro with arguments in C?
A #define MAX(a, b) ((a) > (b) ? (a) : (b))
B #macro MAX(a, b) ((a) > (b) ? (a) : (b))
C #define MAX a, b ((a) > (b) ? (a) : (b))
D define MAX(a, b) ((a) > (b) ? (a) : (b))
Correct Answer:  A. #define MAX(a, b) ((a) > (b) ? (a) : (b))
EXPLANATION

The correct syntax uses #define followed by macro name and parameters, with the replacement text in parentheses.

Test
Q.17 Medium Basics & Syntax
What does the 'extern' keyword indicate in C?
A A variable exists in another source file
B A variable is local to a function
C A variable cannot be modified
D A variable is allocated on the stack
Correct Answer:  A. A variable exists in another source file
EXPLANATION

'extern' declares a variable or function that is defined in another translation unit (source file).

Test
Q.18 Medium Basics & Syntax
What will be the result of the bitwise operation: 5 & 3 in C?
A 1
B 7
C 6
D 4
Correct Answer:  A. 1
EXPLANATION

5 (binary 101) & 3 (binary 011) = 001 (binary) = 1. Bitwise AND operates on each bit position.

Test
Q.19 Medium Basics & Syntax
In C, what is the correct way to pass a variable by reference using pointers?
A void func(int var) { var = 10; }
B void func(int &var) { var = 10; }
C void func(int *var) { *var = 10; }
D void func(int *var) { var = 10; }
Correct Answer:  C. void func(int *var) { *var = 10; }
EXPLANATION

C uses pointers for pass-by-reference. The dereference operator '*var' accesses the actual variable. C++ supports references (&var), but C does not.

Test
Q.20 Medium Basics & Syntax
What is the difference between 'break' and 'continue' statements in C?
A 'break' stops execution while 'continue' skips iteration
B Both have the same function
C 'continue' stops execution while 'break' skips iteration
D Neither has practical use in loops
Correct Answer:  A. 'break' stops execution while 'continue' skips iteration
EXPLANATION

'break' terminates the loop entirely, while 'continue' skips the current iteration and moves to the next one.

Test
IGET
IGET AI
Online · Exam prep assistant
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