NEW
Font size
WorksheetsCode Carnival
Total questions: 25
Worksheet time: 13mins
What will be the output of the following code?
#include<stdio.h>
int main() {
int x = 3;
if (x == 3 || x == 2 * 2 && x != 5) {
printf("Hello\n");
} else { printf("World\n");
}
return 0;
}
How many times will the loop execute?
#include<stdio.h>
int main() {
int i;
for (i = 1; i <= 6; i++) {
if (i % 2 == 0) {
printf("%d ", i++);
}
}
return 0;
}
What will be the output of the following code?
int arr[4] = {1, 2, 3};
printf("%d", arr[3]);
Given the following declaration in C:
int arr[5];
float arr2[3];
Which of the following statements correctly calculates the total number of bytes required to store these arrays, considering the typical memory sizes for int and float (assuming int is 4 bytes and float is 4 bytes on your system)?
What will be the output of the following code?
#include <stdio.h>
int main() {
char str[5] = "Hello";
printf("%s", str);
return 0;
}
What is the output?
int x = 10;
switch (x) {
case 5: printf("Five");
case 10: printf("Ten");
case 15: printf("Fifteen");
}
Which function is used to find the length of a string?
Which of the following loop constructs will result in an infinite loop if the condition is never updated inside the loop body?
What is the output?
#include <stdio.h>
int main() {
int arr[5] = {1, 3, 5, 7, 9};
arr[2] = arr[4] - arr[0];
arr[4] = arr[1] + arr[3];
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
return 0;
}
1 3 4 6 10
Find the output of the following code:
int arr[] = {1, 2, 3, 4, 5};
printf("%d", (arr[2] & arr[3]) | (arr[2] ^ arr[3]));
What is sizeof(arr)/sizeof(arr[0]) for int arr[5]?
What happens if an array index goes out of bounds in C?
What is the output?
char str[ ] = "Hello";
printf("%s", str + 1 + 2);
What will happen if a function in C returns the address of a local variable?
What will be printed when the following code is executed?
char str[ ] = "Programming";
printf("%s", str + sizeof(char) * 2);
Which of the following functions compares two strings lexicographically and ensures that the comparison stops as soon as a difference is found, but also guarantees the correct comparison of binary data (including null bytes) within the strings?
What is wrong with this code?
for(int i = 0; i < 5; i++);
printf("%d ", i);
What will be the output of the following code snippet?
int arr[3] = {'A', 'B', 'C'};
printf("%d", arr[0] + arr[1] + arr[2]);
Find the error in the following program:
#include <stdio.h>
int sum(int a, int b) {
if (a + b > 10)
return;
return a + b;
}
int main() {
int result = sum(5, 6);
printf("%d", result);
return 0;
}
What will be the output of the following code?
for (char ch = 'A'; ch <= 'E'; ch++) {
printf("%c ", ch);
}
Find the output of the following code snippet:
int arr[] = {5, 10, 15, 20};
int sum = 0, i;
for(i = 0; i < 4; i += 2)
sum += arr[i];
printf("%d", sum);
What will be the output of the following C program?
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5) {
if (i % 2 == 0)
continue;
printf("%d ", i);
i++;
}
return 0;
}
Find the output of the following:
char str[] = "Code";
str[1] = 'A';
printf("%s", str);
Spot the error in this code snippet:
#include <stdio.h>
int main() {
const int age;
age = 30;
printf("%d", age);
return 0;
}
How does a compiler differ from an interpreter?
