C Language Test 5

    Question 1Data Type Modifiers

    The long data type modifier is used to:

    Question 2Logical NOT Operator

    What is the value of the expression !0?

    Question 3Nested If Statements

    What is the output of the following C code?

    #include int main() { int a = 5, b = 10; if (a < b) { if (a == 5) { printf("Correct"); } } else { printf("Incorrect"); } return 0; }

    Question 4Infinite Loop

    Which of these will create an infinite loop?

    Question 5Standard Library Header

    Which header file must be included to use sqrt() function?

    Question 6Strings as Arrays

    Which of the following is the correct declaration of a string in C?

    Question 7Dangling Pointer

    When does a dangling pointer occur in C?

    Question 8Structure vs Array

    Which statement is true?

    Question 9fread() Function

    What does this code do?

    #include <stdio.h> struct Data { int x; float y; }; int main() { struct Data d; FILE *fp = fopen("bin.dat", "rb"); fread(&d, sizeof(d), 1, fp); fclose(fp); return 0; }

    Question 10String vs Character

    Which of the following is a string constant in C?

    Question 11Guess the Output - Constant Declaration

    What is the output of the following code?

    #include <stdio.h> #define PI 3.14 int main() { printf("%f", PI * 2); return 0; }

    Question 12C Ternary Operator

    What is the output of the following C code?

    #include <stdio.h> int main() { int age = 20; printf("%s", (age >= 18) ? "Adult" : "Minor"); return 0; }

    Question 13Logical Operators in If

    What is the output of the following C code?

    #include int main() { int temp = 25; if (temp > 20 && temp < 30) { printf("Pleasant"); } else { printf("Extreme"); } return 0; }

    Question 14Loop Control

    Which loop is best suited when the number of iterations is known in advance?

    Question 15Void Functions

    What is true about a void function in C?

    Question 16Sizeof Operator

    If int arr[10]; and sizeof(int) = 4, what will sizeof(arr) return?

    Question 17Function Pointers

    Which is the correct syntax to declare a pointer to a function that takes int as argument and returns int?

    Question 18Union Size

    What will sizeof return?

    #include <stdio.h> union U { int a; double b; char c; }; int main() { printf("%zu", sizeof(union U)); return 0; }

    Question 19fclose() Function

    Why should fclose() always be used after file operations?

    Question 20strchr() Function

    Which standard library function is used to find the first occurrence of a character in a string?