NEW
Font size
WorksheetsC Programming Quiz
Total questions: 50
Worksheet time: 9mins
Which of the following statements about pointers is correct?
A pointer stores the value of a variable.
A pointer stores the memory address of a variable.
A pointer stores the size of a variable.
A pointer is used to add two values.
Which of the following is true about sizeof() operator?
It can be used on any data type.
It returns the size in bits.
It can only be used on variables.
It returns the size in bytes.
What will printf("%d", 5 + 3); output?
53
8
35
5 + 3
What is the format specifier for printing an integer in C?
%c
%s
%d
%f
Which of the following is used to clear memory allocated by malloc()?
clear()
free()
delete()
reset()
What is the output of the following code? int a = 5, b = 3; printf("%d", a % b);
1
2
3
5
Which function is used to dynamically allocate memory in C?
malloc()
free()
sizeof()
realloc()
Consider the following declaration of a 'two-dimensional array in C: char a[100][100]; Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0, the address of a[40][50] is
4040
4050
5040
5050
What will be the output of the following C code?
Error because function name cannot be preceded by const
Sanfoundry.com
Sanfoundry.com is printed infinite times
Blank screen, no output
What will be the final value of x in the following C code?
3.75
Depends on compiler
24
3
What will be the result of code?
16
8
6
4
What is the return value of the function foo when it is called as foo(345, 10) ?
345
12
5
3
What will be the output of C code?
128
-128
Depends on the compiler
None of the mentioned
Which type of function does not return a value?
int
char
void
float
What does the term "pointer to pointer" mean?
It refers to a pointer that stores the address of another pointer.
It is a pointer that stores an integer.
It is a pointer that stores the size of a variable.
It refers to a pointer that can point to multiple values.
Which of the following statements is true for a pointer in C?
A pointer holds the address of another variable.
A pointer stores the value of another variable.
A pointer stores the name of another variable.
A pointer cannot point to another pointer.
Which of the following correctly initializes an array in C?
int arr[] = {1, 2, 3};
int arr[3] = 1, 2, 3;
int arr(3) = {1, 2, 3};
int arr[] = 1, 2, 3;
What is the output of the following code? int a = 1; int b = a << 2; printf("%d", b);
1
2
4
8
What is the default return type of the main() function in C?
int
float
void
char
What is the result of this C program?
10
20
Random value
Compilation error
Tell me which one of the following is true.
An array, each element of which is a pointer to a structure of type node
A structure of 2 fields, each field being a pointer to an array of 10 elements
A structure of 3 fields: an Integer, a float, and an array of 10 elements
An array, each element of which is a structure of type node.
Consider these two functions and two statements S1 and S2 about them.
S1: The transformation from work1 to work2 is valid, i.e., for any program state and input arguments, work2 will compute the same output and have the same effect on program state as work1
S2: All the transformations applied to work1 to get work2 will always improve the performance (i.e reduce CPU time) of work2 compared to work1
S1 is false and S2 is false
S1 is false and S2 is true
S1 is true and S2 is false
S1 is true and S2 is true
Which of the following loops will not run infinitely?
All will run infinitely
None will run infinitely
Only the for loop will not run infinitely
Only the while loop will run infinitely
What does the fragment of the C-program print?
GATE2011
E2011
2011
011
What does the following C-statement declare? int ( * f) (int * ) ;
A function that takes an integer pointer as argument and returns an integer
A function that takes an integer as argument and returns an integer pointer
A pointer to a function that takes an integer pointer as argument and returns an integer.
A function that takes an integer pointer as argument and returns a function pointer
What does the program print?
8, 4, 0, 2, 14
8, 4, 0, 2, 0
2, 0, 4, 8, 14
2, 0, 4, 8, 0
What is #include
Preprocessor directive
Inclusion directive
File inclusion directive
None of the mentioned
All keywords in C are in ____________
LowerCase letters
UpperCase letters
CamelCase letters
None of the mentioned
What is the meaning of the following C statement? printf("%10s", state);
10 spaces before the string state is printed
Print empty spaces if the string state is less than 10 characters
Print the last 10 characters of the string
None of the mentioned
What will happen if the following C code is executed?
It will cause a compile-time error
It will cause a run-time error
It will run without any error and prints 3
It will experience infinite looping
What is the correct syntax for declaring a pointer to a function that returns an int and takes int as an argument?
int (p)();
int p(int);
int (p)(int);
int p(int);
Which function in C is used to compare two strings?
strcmp()
strcat()
strcpy()
strlen()
What is the output of this code?
3
5
10
15
What is the size of an integer (int) in C on a 32bit system?
2 bytes
4 bytes
1 byte
8 bytes
Which of the following functions in C is used to read formatted input?
scanf()
printf()
gets()
puts()
Which of the following declaration is not supported by C language?
String str;
char *str;
float str = 3e2;
Both "String str;" and "float str = 3e2;"
What is the output of this code?
9
10
11
Undefined behavior
What is the result of this program as it is executed?
15
16
17
18
What will printf("%d", 12 | 5); output?
12
5
13
17
What will this code print?
5
10
15
Undefined behavior
What will be the output of the C code?
H
e
l
o
What is the result of sizeof(double) on most systems?
2
4
8
16
What is the output of the following code? int a = 7; printf("%d", a >> 1);
3
7
14
1
Which function is used to deallocate memory in C?
malloc()
free()
calloc()
sizeof()
Which of the following is a correct declaration of a function pointer?
int func(int);
int (func)(int);
int func(int );
int func(int );
What is the correct syntax to declare a variable in C?
int x;
int x =;
int x:
x = int;
The C-preprocessors are specified with _________ symbol.
#
$
" "
&
what is the value returned by f(1)?
5
6
7
8
Which of the following is used to allocate a block of memory in C?
malloc()
calloc()
realloc()
all of the above
Which header file is needed to use dynamic memory allocation functions?
stdio.h
stdlib.h
malloc.h
memory.h
