0% found this document useful (0 votes)
9 views4 pages

Wa0028.

Uploaded by

neonboywastaken
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Wa0028.

Uploaded by

neonboywastaken
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

School of Computing and Data Science

Sai University
Introduction to Programming
Test-2

1. What is the reason for a segmentation fault in a C program?


(a) Array index out of bounds
(b) Incorrect data type
(c) Missing semicolon
(d) Infinite loop
2. Which of the following will cause a compilation error?
(a) Using an undeclared variable
(b) Using an integer in a printf statement
(c) Using %d to print a float
(d) Writing a comment using //
3. What will be the output of the following code?

#include<stdio.h>
int main() {
int x = 5;
printf("%d", x++);
return 0;
}

(a) 5
(b) 6
(c) Compilation Error
(d) Runtime Error

4. Which of the following statements about arrays is correct?


(a) Array elements are stored in contiguous memory locations
(b) Arrays can store elements of different data types

1
(c) Array size can be changed dynamically in C
(d) Arrays in C are always passed by value to functions
5. What would be the output of the following code?

#include<stdio.h>
int main() {
char ch = ’A’;
printf("%d", ch);
return 0;
}

(a) 65
(b) A
(c) Compilation Error
(d) Random value

6. Which of the following causes a compilation error?


(a) Forgetting to include #include¡stdio.h¿
(b) Using single quotes for a string
(c) Assigning an int value to a float variable
(d) Declaring a variable without a data type
7. What would be the output of the following code?

#include<stdio.h>
int main() {
int a = 10;
if(a = 0)
printf("Zero");
else
printf("Non-zero");
return 0;
}

(a) Zero
(b) Non-zero
(c) Compilation Error
(d) Runtime Error

8. Which of the following will lead to undefined behavior?


(a) Division by zero
(b) Using a variable before initialization

2
(c) Both (a) and (b)
(d) None of the above
9. What would be the output of the following code?

#include<stdio.h>
int main() {
int a = 2, b = 5, c = 10;
printf("%d", a * b / c);
return 0;
}

(a) 1
(b) 0
(c) 2.5
(d) Compilation Error

10. Which of the following will cause a logical error but not a compilation
error?
(a) Using = instead of ==
(b) Forgetting to declare a variable
(c) Missing return statement in int main()
(d) Incorrect printf format specifier
11. What is wrong with the following code?

#include<stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[5]);
return 0;
}

(a) Nothing
(b) Array index out of bounds
(c) Syntax error
(d) Compilation Error

12. What is the correct way to declare a constant variable in C?


(a) const int x = 10;
(b) int const x = 10;
(c) Both (a) and (b)

3
(d) None of the above
13. What would be the output of the following code?

#include<stdio.h>
int main() {
int a = 5, b = 10;
printf("%d", a < b ? a : b);
return 0;
}

(a) 5
(b) 10
(c) Compilation Error
(d) None of the above

14. Which of the following causes a segmentation fault?


(a) Accessing array out of bounds
(b) Division by zero
(c) Forgetting return 0 in main()
(d) Incorrect use of printf
15. What would be the output of the following code?

#include<stdio.h>
int main() {
int arr[] = {1, 2, 3, 4, 5};
printf("%d", arr[3]);
return 0;
}

(a) 4
(b) 3
(c) 5
(d) Compilation Error

You might also like