
C quiz
Authored by Giri A
Computers
University
Used 5+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int *ptr = arr;
ptr = ptr + 2;
printf("%d ", *(ptr + 1));
return 0;
}
30
40
50
20
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, world!";
printf("%d", strlen(str));
return 0;
}
13
14
12
Undefined behaviour
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include <stdio.h>
#include <stdlib.h>
int main() {
int *arr = (int *)calloc(3, sizeof(int));
arr[1] = 10;
arr[2] = 20;
free(arr);
printf("%d", arr[2]);
return 0;
}
0
10
20
Undefined behavior
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include <stdio.h>
#include <stdlib.h>
int main() {
int *arr = (int*)malloc(10 * sizeof(int));
free(arr);
arr[0] = 5;
printf("%d", arr[0]);
return 0;
}
It will print 5.
It will print 0.
It will give a runtime error due to accessing freed memory.
It will give a compilation error.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include <stdio.h>
int main() {
int x = 5; // Binary: 0101
x = x << 1;
printf("%d", x);
return 0;
}
5
10
20
2
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include <stdio.h>
struct Person {
char name[30];
int age;
}
int main() {
struct Person persons[2] = {{"John", 25}, {"Jane", 30}};
printf("%d", persons[1].age);
return 0;
}
persons[1].name
persons[0].age
persons[1].age
persons[0].name
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
#include <stdio.h>
int main() {
for (int i = 0; i >= 0; i++) {
printf("%d ", i);
}
return 0;
}
The loop will terminate after one iteration.
The loop will run forever.
The loop will run 0 iterations.
It will cause a segmentation fault.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?