NEW
Font size
WorksheetsCoding club Summit Online Quiz
Total questions: 15
Worksheet time: 15mins
In C, what is the purpose of the restrict keyword
Specifies that a pointer is the only pointer to the data
Allocates memory dynamically
Declares a variable as a constant
Specifies that a variable cannot be modified
What is the primary use of the setjmp and longjmp functions in C
Memory allocation
Exception handling
Dynamic linking
File I/O operations
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
printf("%p\t%p", p, a);
}
Same address is printed
Different address is printed
Compile time error
Nothing
What will be the output of the following code snippet?
#include <stdio.h>
int main() {
int a, b = 5;
a = b + NULL;
printf("%d", a);
return 0;
}
Compilation Error
Runtime Error
Logical Error
None of these
What is the output of the following code snippet?
#include <stdio.h>
int main() {
int x = 10;
int *ptr = &x;
printf("%d", *ptr);
return 0;
}
Memory address of x
10
Compilation error
None of these
What will be the output of the following C code?
void main() {
char *p;
p = "Hello";
printf("%c\n", &p);
}
Hello
E
Some address will be printed
None of these
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 97, *p = &i;
ABC(&i);
printf("%d ", *p);
}
void ABC(int *p)
{
int j = 2;
p = &j;
printf("%d ", *p);
}
2 97
2 2
Compile time error
Segmentation fault/code crash
Which of the following is FALSE about typedef
typedef follow scope rules
typedef defined substitutes can be redefined again. (Eg: typedef char a; typedef int a;)
You cannot typedef a typedef with other term.
All of the mentioned
void * malloc(size_t n) returns:
Pointer to n bytes of uninitialized storage
NULL if the request cannot be satisfied
Nothing
Both a & b are true
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 10;
int *const p = &i;
XYZ(&p);
printf("%d\n", *p);
}
void XYZ(int **p)
{
int j = 11;
*p = &j;
printf("%d\n", **p);
}
10 11
Compile time error
Segmentation fault/code-crash
None of these
What will be the output of the following C code?
#include <stdio.h>
void m(int *p)
{
int i = 0;
for(i = 0;i < 5; i++)
printf("%d\t", p[i]);
}
void main()
{
int a[5] = {6, 5, 3};
m(&a);
}
0 0 0 0 0
6 5 3 0 0
Run time error
6 5 3 junk junk
Output of following program?
# include <stdio.h>
void fun(int *ptr)
{
*ptr = 30;
}
int main()
{
int y = 20;
fun(&y);
printf("%d", y);
return 0;
}
20
30
Compiler Error
Runtime Error
Assume that float takes 4 bytes, predict the output of following program.
#include <stdio.h>
int main()
{
float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 3;
printf("%f ", *ptr2);
printf("%d", ptr2 - ptr1);
return 0;
}
90.500000 3
90.500000 12
10.000000 12
0.500000 3
What is the output of this C code?
int main()
{
char *p = NULL;
char *q = 0;
if (p)
printf(" p ");
else
printf("nullp");
if (q)
printf("q\n");
else
printf(" nullq\n");
}
nullp nullq
Depends on the compiler
x nullq where x can be p or nullp depending on the value of NULL
p q
What is the output of this C code?
int *f();
int main()
{
int *p = f();
printf("%d\n", *p);
}
int *f()
{
int j = (int)malloc(sizeof(int));
*j = 10;
return j;
}
Undefined behaviour
Compile time error
Segmentation fault/runtime crash since pointer to local variable is returned
None of these
