wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

SASI -BATCH 3-DAY6-FN(25.11.23)

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.
#include<stdio.h> int main() { const int a = 5; const int *ptr; ptr = &a; *ptr = 10; printf("%d\n", a); return 0; }
a)
Compilation error
b)
Garbage Value
c)
Address
d)
5
2.
#include<stdio.h> int main() { printf("%d", sizeof(void *)); return 0; }
a)
1
b)
compilation error
c)
Runtime error
d)
4
3.
#include<stdio.h> int main() { int a = 10, b = 6; int *ptr; ptr = &b; printf(" %d ", a **ptr); return 0; }
a)
Pointer type error
b)
Run time error
c)
Compilation error
d)
60
4.
#include<stdio.h> int main(){ char array[5] = "Knot", *ptr, i, *ptr1; ptr = &array[1]; ptr1 = ptr + 3; *ptr1 = 101; for(i = 0; i < 4;i++) printf("%c", *ptr++); return 0; }
a)
not
b)
Knot
c)
note
d)
garbage value
5.
#include<stdio.h> int main(){ int i = 5; void *vptr; vptr = &i; printf("\nValue of iptr = %d ", *vptr); return 0; }
a)
5
b)
garbage address
c)
garbage value
d)
Compile time error
6.
#include<stdio.h> int main() { int num = 10; // assume the address location is 2293436 printf("num = %d address = %u ",num, &num); num++; printf("\tnum = %d address = %u",num, &num); return 0; }
a)
Compilation error
b)
num = 10 address = 2293436 num = 11 address = 2293438
c)
num = 10 address = 2293436 num = 11 address = 2293440
d)
num = 10 address = 2293436 num = 11 address = 2293436
7.
#include<stdio.h> int main(){ char *str1 = "First"; char *str2 = "Second"; switch(*str1){ case "First": printf("USAIN BOLT"); break; case "Second": printf("JUSTIN GATLIN"); break; default: printf("Others"); } return 0; }
a)
USAIN BOLT
b)
JUSTIN GATLIN
c)
Compilation Error
d)
Others
8.
#include<stdio.h> int main(){ char *str = "ABCD"; switch(*str + 2){ case 'A': printf("Apple"); break; case 'B': printf("BOOK"); break; case 'C': printf("CLOUD"); break; case 'D': printf("DELL"); break; } return 0; }
a)
CLOUD
b)
BOOK
c)
APPLE
d)
Compilation Error
9.
#include<stdio.h> int main(){ char ch = '\0'; switch(ch){ case NULL: printf("Empty \0"); break; case ' ': printf("Empty Empty"); break; case '0': printf("Empty 0"); break; default: printf("Nothing"); } return 0; }
a)
Empty \0
b)
Empty Empty
c)
Empty 0
d)
None of the above
10.
#include <stdio.h> int main() { int x = 10000; double y = 56; int *p = &x; double *q = &y; printf("p and q are %d and %d", sizeof(p), sizeof(q)); return 0; }
a)
p and q are 4 and 4
b)
p and q are 4 and 8
c)
compiler error
d)
p and q are 2 and 8
11.
#include <stdio.h> int main() { int x = 10000; double y = 56; int *p = &x; double *q = &y; printf("p and q are %d and %d", sizeof(p), sizeof(q)); return 0; }
a)
p and q are 4 and 4
b)
p and q are 4 and 8
c)
compiler error
d)
p and q are 2 and 8
12.
#include <stdio.h> int main() { int arr[5] = {1, 2, 3, 4, 5}; int *ptr = &arr[0]; ptr += 3; printf("%d", *ptr); return 0; }
a)
4
b)
5
c)
compiler error
d)
undefined behaviour
13.
#include <stdio.h> int main() { int *ptr = (int *)malloc(sizeof(int)); *ptr = 42; free(ptr); printf("%d", *ptr); return 0; }
a)
prints 42
b)
prints 0
c)
Causes a segmentation fault
d)
compilation error
14.
#include <stdio.h> int main() { char *str = "Dynamic"; str[2] = 'x'; printf("%s", str); return 0; }
a)
Segmentation fault
b)
Runtime error
c)
Prints "Dyxnamic"
d)
Prints "Dynamic"
15.
#include <stdio.h> int main() { int matrix[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; printf("%p", (void*)&matrix[1][1]); return 0; }
a)
Execution Time
b)
Memory Address
c)
McCabe Cyclomatic Complexity
d)
Code Coverage