NEW
Font size
WorksheetsTECH - C
Total questions: 30
Worksheet time: 50mins
Which of the following declarations is/are correct for creating an “integer array of 5 elements”?
(Assume the size of integer to be 2 bytes)
int *a = (int *)malloc(5);
int **a = (int *)malloc(10);
int a[] = (int *)malloc(10);
int (*a)[5];
What would be the output of the following program?
(Assume the size of integer to be 2 bytes)
char ch = ‘A’;
int a = ‘a’;
if(sizeof(ch) > ch - a){
printf(“YES!”);
}
else{
printf(“NO!”);
}
YES!
NO!
What is the size(in bytes) of the following structure?
(Assume the size of integer to be 2 bytes)
struct Student{
int age;
int marks;
char class;
};
7 bytes
6 bytes
8 bytes
5 bytes
Which of the following statements is FALSE?
calloc() is slower compared to malloc()
free() is used to remove unwanted heap memory
There are 3 passing techniques in C:
i) Pass by Value ii) Pass by Reference
iii) Pass by Address
We can use return statement in a function returning void
Choose the correct conclusion for the following given program:
#include <stdio.h>
int main()
{
int x;
scanf("%d",&x);
if(x < 0){
printf("Undefined");
}
else{
int factorial = 1;
for(int i = 1; i<=x; i++){
factorial *= i;
}
printf("The factorial of %d is : %d",x,factorial);
}
return 0;
}
The program correctly returns the factorial of any given number
The program correctly returns the factorial of any number greater than 1
The program correctly returns the factorial of any number greater than 0
None of the above
The following program finds the second maximum element in the array.
Which of the following statements should be the correct function definition for the function “calculate()” in the given program?
//modify the function definition below
___calculate(_______){
int sum = 0;
for(int i = 0; i<n; i++){
sum += (*arr)[i];
}
return sum;
}
int calculate(int (*arr)[], int n)
int calculate(int *arr[n])
int calculate(int arr[n])
int calculate(int *arr[], int n)
Choose a correct statement about a Multidimensional array and pointer.?
int *ptr[N] is an array of N integer pointers. Size is N * sizeof(1*int).
int (*ptr)[N] is a pointer to an array of N elements. Size of ptr is size of 1 integer
Both option A & option B.
None of these
Is it possible to write a C Program that prints “Hello World!” without using a statement terminator(;)? (Assume that you don’t need to write a return statement)
Yes
No
Cannot Be Determined
Which of the following statements is incorrect?
We cannot dereference a void pointer
A global and a local variable can have the same name
The sizeof(x) function returns the size of ‘x’
It is a good programming practice to set a dangling pointer to point to NULL
What would be the value displayed by the printf() function in the following code snippet?
(Assume size of integer to be 2 bytes)
#include <stdio.h>
int main()
{
int a = 1;
int b = sizeof(a++);
printf("%d %d",b,a);
return 0;
}
4 1
4 2
2 1
Compiler Dependent
printf("%d", scanf("%d", &num)); is a valid C statement.
TRUE
FALSE
What should be the values of the variables ‘a’ and ‘b’ so that the following program produces an output “RCCIIT”?
int a = 5;
int b = 1;
if(a + b - (a/b) * b, ++a, --b){
printf("RCCIIT");
}
else{
printf("TIICCR");
}
a = 0, b = 0
a = 1, b = 0
a = 1, b = 1
Cannot Be Determined
Consider the code fragment written in C below :
void f (int n)
{
if (n <=1) {
printf ("%d", n);
}
else {
f (n/2);
printf ("%d", n%2);
}
}
What does f(225) print?
11100001
11110001
11110000
11000011
Which of the following is the correct way of declaring a variable?
int alph@b3t = 5;
float 34var = 4.7f;
char strlen = 97;
int default = 0;
What would be the output of the following pseudocode?
a = 0;
if(a = 0){
if(++a){
print("Inside If");
}
else{
print("Inside Else")
}
}
else
print("Outside Else");
Inside If
Inside Else
Outside Else
Inside ElseOutside Else
What does the following program return for fun(6) ?
int fun(int n){
if(n <= 1)
return 1;
else{
return n + n*fun(n--);
}
}
720
445
Infinite Loop
Stack Overflow
How many function calls will be evaluated for fun(6) for the following program?
int fun(int n){
if(n <= 1)
return 1;
else{
return 5*fun(n-3) + 3*fun(n-2);
}
}
8
7
45
50
Which of the following is not a primitive data type?
Integer
Float
Character
Pointer
How many times will the following loop execute? (MARK 2)
int i,j;
i = 1;
j= 1;
for( ; i<=n; i = i+j, j++);
sqrt(n)
log(n)
n/2
loglog(n)
What is the correct description for the variable fun declared below?
int *(*fun)(int **)
fun is a function that takes a pointer to a pointer to integer as argument and returns a pointer to a pointer to integer
fun is a pointer to a function that takes a pointer to a pointer to integer as argument and returns a pointer to integer
. fun is a pointer to a function that takes a pointer to integer and returns a pointer to pointer to integer
. fun is a function that takes a pointer to integer and returns a pointer to integer
what will be the output of the below program?
#include <stdio.h>
int main()
{
int x = 2;
switch (x) {
x--;
switch (x) {
case 1:
printf("CSE");
break;
case 2:
printf("DEPARTMENT");
break;
case 3:
printf("INNOVISION");
break;
default:
printf(“2021”);
}
}
return (0);
}
CSE
DEPARTMENT
No Output
INNOVISION
If malloc() and calloc() are not type casted, the default return type is ___________
void*
void**
int*
char*
If the space in memory allocated by malloc is not sufficient, then an allocation fails and returns ___________
NULL pointer
Zero
Garbage value
The number of bytes available
Loss in precision occurs while typecasting from____________
char to short
float to double
long to float
float to int
Output Will be:
#include <stdio.h>
int main(){
int x = 2, i = 0;
do {
x = x++;
i++;
} while (i != 3);
printf("%d\n", x);
}
Undefined behaviour
Output will be 3
Output will be 6
Output will be 5
Which return type cannot return any value to the
calling function?
int
float
void
double
Which operator is used to dereference a pointer?
&
*
–>
None of these
The __ operator informs the compiler that the variable is a pointer variable.
&
*
Both
None Of These
After the last statement of a function executes, control passes to the ____
calling function
beginning of this function
main function
function whose code immediately follows this function's code
What is the output of C Program.?
int main()
{
int ary[2][2][3] = {
{{1,2,3},{4,5,6}},
{{7,8,9},{10,11,12}}
};
printf("%d",*(*(*(ary+1)+ 1)+2));
return 0;
}
10
11
12
Compilation error
