Which of the following language is the predecessor to C programming language?
- A
A Language
- B
B Language
- C
BCPL
- D
C++ Language
Master C programming with 120+ curated MCQs covering basics, pointers, arrays, structures, file I/O, and more. Perfect for exams, interviews, and placement preparation.
Which of the following language is the predecessor to C programming language?
A Language
B Language
BCPL
C++ Language
C programming language was developed by whom?
Dennis Ritchie
Ken Thompson
Bill Gates
Peter Norton
In which year was C developed?
1972
1970
1976
1979
C is a __________ language.
High level
Low level
Middle level
Machine level
C language is available for which operating systems?
DOS
Windows
Unix
All of these
Which symbol is used to denote a pre-processor statement in C?
|
#
^
;
Which of the following are tokens in C?
Keywords
Variables
Constants
All of these
What is the valid range of numbers for an int type in C?
0 to 256
-32768 to +32767
-65536 to +65536
None of these
Which of the following is a scalar data type?
Float
Union
Array
Pointer
Which symbol is used as a statement terminator in C?
!
#
$
;
A character constant should be enclosed between __________.
Single quotes
Double quotes
Both A and B
None of these
What is the maximum length of a variable name in C?
8
16
32
64 (ANSI standard)
What is the result of 5 % 2 in C?
2
1
0
3
Which operator is used to access the address of a variable?
*
&
%
->
What is the associativity of the assignment operator (=) in C?
Left to right
Right to left
Both
None
Which operator is used for logical AND in C?
&
&&
|
||
What is the size of an int data type in C (typically on a 32-bit system)?
2 bytes
4 bytes
8 bytes
1 byte
What does the 'sizeof' operator return?
The size of a variable in bytes
The address of a variable
The value of a variable
The type of a variable
Which statement is used to exit a loop in C?
break
continue
return
exit
What is the output of the following code? int a = 10; if(a<10) printf('Yes'); else printf('No');
Yes
No
Error
None
Which loop is guaranteed to execute at least once?
for
while
do-while
All of these
What is the use of the 'switch' statement in C?
To implement multi-way branching
To loop until a condition is met
To define a function
To declare variables
What is the default case in a switch statement?
It executes when no case matches
It executes before all cases
It is mandatory
It executes after all cases
What is the output of: for(i=0;i<3;i++) printf('%d',i);
0 1 2
0 1 2 3
1 2 3
No output
Which index is used to access the first element of an array in C?
1
0
-1
Any
What is the size of int arr[10] if each int is 4 bytes?
20 bytes
40 bytes
10 bytes
4 bytes
Which of the following correctly declares a 2D array in C?
int arr[3][4];
int arr[3,4];
int arr(3)(4);
int arr[3] [4];
What is the name of the first element of an array?
arr[0]
arr[1]
arr
arr[last]
What is the output of: int a[] = {1,2,3}; printf('%d', a[2]);
1
2
3
Error
What is the maximum number of dimensions an array can have in C?
1
2
No limit
3
What is the return type of the main() function in C?
int
void
float
char
Which keyword is used to define a function in C?
function
def
void
There is no keyword; functions are defined by their return type and name
What is the scope of a variable declared inside a function?
Local to the function
Global
File scope
Block scope
Which of the following is a valid function prototype?
int sum(int a, int b);
sum(int a, int b) int;
int sum(a,b);
void sum(int a, b);
What is the purpose of the 'return' statement in a function?
To exit the function and optionally return a value
To declare a variable
To call another function
To print something
What is recursion in C?
Function calling itself
Function calling another function
Function without a return type
Function with multiple parameters
What is a pointer in C?
A variable that stores the address of another variable
A data type
A function
A loop
Which operator is used to get the address of a variable?
*
&
%
->
Which operator is used to dereference a pointer?
*
&
%
->
What is the size of a pointer in C (on a 64-bit system)?
2 bytes
4 bytes
8 bytes
1 byte
What is a NULL pointer?
A pointer that points to nothing
A pointer that points to address 0
A pointer that is not initialized
Both A and B
What is a pointer to a function?
A pointer that stores the address of a function
A function that returns a pointer
A data type
A loop
What is a structure in C?
A collection of variables of different data types under a single name
An array of similar data types
A pointer
A function
How is a union different from a structure?
Union members share the same memory location; structure members have separate memory
Union can hold only one data type
Structure members share memory
There is no difference
Which operator is used to access structure members via a pointer?
.
->
&
*
How do you define a structure in C?
struct { int x; float y; } variable;
structure { int x; float y; } variable;
typedef struct { int x; float y; } variable;
Both A and C
What is the size of a union?
Sum of sizes of all members
Size of the largest member
Average of sizes
Size of the first member
Can you pass a structure to a function by value in C?
Yes
No
Only by reference
Only pointers
Which library is used for file I/O in C?
stdio.h
stdlib.h
string.h
math.h
What is the function to open a file in C?
fopen()
open()
file_open()
create_file()
Which mode is used to open a file for reading in C?
r
w
a
rw
What is the function to close a file in C?
fclose()
close()
file_close()
clos()
Which function is used to read a line from a file in C?
fgets()
fgetline()
gets()
scanf()
What does feof() function do?
Checks for end-of-file
Reads a file
Writes to a file
Closes a file
What is the output of #define SQUARE(x) (x*x) when SQUARE(3) is used?
9
6
12
Error
What is the purpose of #include directive in C?
To include header files
To define macros
To conditionally compile
To declare functions
Which of the following is a preprocessor directive?
#ifdef
#undef
#pragma
All of these
What is the use of #ifndef?
To check if a macro is not defined
To check if a macro is defined
To include a file
To define a macro
What is the purpose of #pragma?
To provide additional instructions to the compiler
To define a macro
To include a header
To conditionally compile
What happens if we use #include <filename.h> vs #include 'filename.h'?
<> searches in system directories, '' searches in current directory first
Both are same
<> searches in current directory, '' in system directories
None
Which function is used to allocate memory dynamically in C?
malloc()
calloc()
realloc()
All of these
What is the difference between malloc() and calloc()?
malloc allocates uninitialized memory; calloc allocates zero-initialized memory
malloc takes one argument; calloc takes two
Both A and B
They are identical
Which function is used to free dynamically allocated memory?
free()
delete()
release()
dealloc()
What is the return type of malloc()?
void*
int*
char*
float*
What does realloc() do?
Changes the size of previously allocated memory
Allocates new memory
Frees memory
Initializes memory
What is a memory leak in C?
Memory that is allocated but never freed
Memory that is freed twice
Memory that is not accessible
Memory that is corrupted
Which header file is required for string functions in C?
string.h
stdlib.h
stdio.h
ctype.h
What is the length of the string 'Hello' in C?
5
6
4
7
Which function copies a string in C?
strcpy()
strncpy()
strdup()
All of these
What is the difference between strcat() and strncat()?
strcat concatenates full string; strncat appends a specified number of characters
strcat is faster
strncat is safer
Both A and C
Which function compares two strings in C?
strcmp()
strncmp()
Both A and B
strdiff()
What is the output of strlen('Hello World')?
11
10
12
0
What is a linked list in C?
A dynamic data structure consisting of nodes with pointers
An array of structures
A type of file
A function
What is a stack in C?
A LIFO (Last In First Out) data structure
A FIFO data structure
An array
A linked list
What is a queue in C?
A FIFO (First In First Out) data structure
A LIFO data structure
A file
A function
What is the 'volatile' keyword used for in C?
To tell the compiler that a variable's value may change unexpectedly
To make a variable read-only
To declare a static variable
To initialize a variable
What is a typedef in C?
To create an alias for a data type
To define a function
To declare a variable
To create a structure
What is the purpose of 'static' keyword inside a function?
To make the variable retain its value across function calls
To make the variable global
To initialize the variable to 0
To make the function inline
What is a bit field in C?
A structure member that occupies a specified number of bits
An array of bits
A pointer to bits
A function that manipulates bits
What is the 'const' qualifier used for in C?
To make a variable read-only
To declare a constant
To prevent modification
All of the above
What is the default return type of a function in C if not specified?
int
void
float
char
Which escape sequence is used for a newline in C?
\n
\t
\r
\b
What is the size of a char in C?
1 byte
2 bytes
4 bytes
8 bytes
Which data type is used to store a wide character in C?
wchar_t
char
short
long
What is the result of 10/3 in integer arithmetic?
3.33
3
4
0
Which operator is used to check if two values are equal in C?
=
==
!=
===
What is the output of: int i=1; switch(i) { case 1: printf('One'); break; default: printf('Default'); }
One
Default
OneDefault
Error
Which loop is most suitable when the number of iterations is known?
for
while
do-while
All
What is the output of: int a[5]={1,2}; printf('%d', a[3]);
0
3
Garbage value
Error
How can you pass an array to a function in C?
By passing the array name
By passing a pointer to the first element
Both A and B
By passing the array size
What is the default storage class of a variable declared inside a function?
auto
static
register
extern
Which keyword is used to return a value from a function?
return
exit
break
continue
What is pointer arithmetic?
Adding or subtracting integers to a pointer to move to other memory locations
Multiplying pointers
Dividing pointers
Comparing pointers
What is a double pointer in C?
A pointer to a pointer
A pointer to a structure
A pointer to an array
A function pointer
What is the keyword to define a structure in C?
struct
union
typedef
class
Can a structure contain a pointer to itself?
Yes
No
Only if typedef is used
Only in C++
Which function writes a character to a file in C?
fputc()
fprintf()
putc()
All of these
What is the file pointer type in C?
FILE*
file*
FILE
File
What is the output of #define VALUE 5+5 when used as int x = VALUE * 2;
20
15
10
Error
Which directive is used to define a macro in C?
#define
#undef
#ifdef
#include
Which function is used to allocate memory for an array of elements in C?
calloc()
malloc()
realloc()
free()
What is the purpose of free() function?
To release allocated memory
To allocate memory
To reallocate memory
To initialize memory
Which function converts a string to uppercase in C? (Standard C does not have a built-in one, but we'll ask about toupper)
toupper()
strupr()
strtoupper()
toupper() is for characters, not strings; no standard function
What is the difference between strtok() and strchr()?
strtok splits strings, strchr finds a character
strchr splits strings, strtok finds a character
Both split strings
Both find characters
What is a recursive function?
A function that calls itself
A function that calls another function
A function that returns void
A function that has no parameters
What is the use of 'extern' keyword in C?
To declare a variable that is defined in another file
To define a static variable
To make a variable global
To initialize a variable
What is the minimum number of characters in a variable name in C?
1
2
3
No minimum
Which of the following is not a valid data type in C?
int
float
string
double
What is the precedence of the logical NOT operator (!) in C?
Highest
Lowest
Same as relational
None
Which statement is used to skip the rest of the current iteration in a loop?
continue
break
return
goto
What is the name of the C function to sort an array? (Standard C doesn't have one, but we ask about qsort)
sort()
qsort()
bubble_sort()
No standard sorting function
What is an inline function?
A function that is expanded at the call site to reduce function call overhead
A function that cannot be called
A function that returns void
A function with no parameters
What is a void pointer?
A pointer that can point to any data type
A pointer that points to nothing
A pointer that cannot be dereferenced
Both A and C
Can you define a structure inside another structure in C?
Yes
No
Only with typedef
Only in C++
Which function is used to read a character from a file in C?
fgetc()
fread()
getc()
All of these
What is the purpose of #error directive?
To produce a compile-time error message
To stop preprocessing
To include a file
To define a macro
What is the result of calling free() with a NULL pointer?
Nothing happens
Memory leak
Segmentation fault
Error
Which function returns the length of a string in C?
strlen()
size()
length()
strlength()
What is the use of 'register' keyword in C?
To suggest the compiler to store the variable in a CPU register
To make a variable read-only
To make a variable global
To define a function
What is a function pointer?
A pointer that stores the address of a function
A function that returns a pointer
A pointer to an array
A data type