C Programming Quiz by azka.xdlabin QuizMarch 4, 2025 C Programming Quiz 1 / 100Which of the following is required to prevent infinite recursion? A goto statement A break statement A base condition A loop inside the function 2 / 100What is a Union in C ? A special type of array A data structure that allows only integer values A collection of unrelated functions A user-defined data type where all members share the same memory location 3 / 100What is a structure in C? A function that holds multiple variables A collection of variables of the same data type A keyword for memory allocation A collection of variables of different data types under one name 4 / 100What is the correct syntax to declare a pointer to an integer? int ptr*; int *ptr; *int ptr; ptr int*; 5 / 100Which statement is not a jump statement? goto switch continue break 6 / 100What is a function prototype in C? A declaration of a function before its definition A function without a return value A function that runs automatically A built-in function in C 7 / 100What happens if break is used outside a loop or switch? It works normally It causes a compilation error It is ignored by the compiler It causes an infinite loop 8 / 100Where can continue be used? Inside if-else blocks Inside functions only Inside loops only Inside switch statements 9 / 100What is a function in C? A block of code that performs a specific task A variable that stores multiple values A keyword used for iteration A loop structure 10 / 100What is the purpose of a function prototype? To improve execution speed To inform the compiler about the function before its use To define the function To prevent function calls 11 / 100What will happen if malloc() fails to allocate memory? Undefined behavior Returns 0 Program crashes Returns NULL 12 / 100What is the correct syntax to declare a function in C? void functionName(); functionName() void; void = functionName(); declare function functionName(); 13 / 100What is the output of this program? 1 2 3 Compilation Error 3 2 1 1 14 / 100How do you terminate a loop immediately in C? exit(0) continue return break 15 / 100Which of the following is a conditional statement in C? do-while if while for 16 / 100What is the correct syntax for a for loop? for(initialization; condition; update) { body } for(update; initialization; condition) { body } for(condition; initialization; update) { body } for(initialization, update, condition) { body } 17 / 100How do you define a union in C? structure Data { int a; float b; }; data union { int a; float b; }; union Data { int a; float b; }; Data union { int a; float b; }; 18 / 100How do you define a structure in C? struct { int x; float y; }; struct MyStruct { int x; float y; }; structure MyStruct { int x; float y; }; define struct { int x; float y; }; 19 / 100What is a structure in C? A type of loop A user-defined data type that groups different data types together A function that initializes variables A type of pointer 20 / 100What is the correct syntax to declare a variable in C? int = x; variable x; x int; int x; 21 / 100What is the main difference between a struct and a union? There is no difference between them A union allows multiple values to be stored simultaneously A struct uses less memory than a union A struct stores all its members separately, while a union shares memory among all members 22 / 100Which of the following is the correct syntax for an if statement in C? if x > 5 then printf("Hello"); if (x > 5) printf("Hello"); if x > 5 { printf("Hello"); } if (x > 5) { printf("Hello"); } 23 / 100Which of the following is a correct way to free allocated memory? delete ptr; remove(ptr); free(ptr); clear(ptr); 24 / 100What is the output of the following code? 10 Compilation error 15 5 25 / 100Which of the following statements is true about structures? A structure is the same as a class in C++ A structure can contain functions A structure cannot have another structure as a member A structure can have an array as a member 26 / 100What is the output of the following program? 1 2 4 5 1 2 3 4 5 1 2 1 2 3 27 / 100How do you access a structure member? struct.member() struct->member struct.member struct:member 28 / 100What is the output of this program? Hello World Hello World Compilatoin error 29 / 100What is the correct way to call a function? execute functionName(); functionName = call; functionName(); call functionName; 30 / 100How do you declare an enum variable in C? enum c = Color; enum Color c; c = enum Color; Color c; 31 / 100What will happen if you try to dereference a NULL pointer? It will print NULL It will print 0 Program will crash Compilation error 32 / 100 Which of the following is NOT a valid format specifier in C? %p% %Lf %lf %d 33 / 100What is Recursion in C ? A function that runs infinitely A function with no parameters A function with multiple return values A function that calls itself 34 / 100How do you declare an integer array of size 5 in C? int arr(5); array int arr[5]; int arr[5]; int[5] arr; 35 / 100What does the break statement do? Stops execution of a program Jumps to a labeled statement Skips the current iteration of a loop Exits a loop or switch statement 36 / 100What will happen if a function is used without a prototype in C? The program will run normally The function will execute twice The program may give a compilation warning or error The function will be ignored by the compiler 37 / 100What is an array in C? A pointer that stores memory addresses A function that stores multiple values A collection of variables of different data types A collection of variables of the same data type stored in contiguous memory 38 / 100What happens if you access an array index that is out of bounds? It will always print 0 It may cause unpredictable behavior (segmentation fault) The program will terminate immediately It will cause a compilation error 39 / 100Can a structure contain a pointer to itself? No Only in C++ Only if the pointer is initialized Yes 40 / 100What is a dangling pointer? A pointer that stores an address in hexadecimal A pointer that is uninitialized A pointer that points to a deallocated memory location A pointer that points to NULL 41 / 100What is the format specifier for printing an integer in C? %d %c %s %f 42 / 100What is the keyword used to define a structure in C? struct structure class typedef 43 / 100Which loop is used when the number of iterations is known? do-while while for switch 44 / 100What happens if recursion doesn't have a base case? The compiler automatically stops execution The program crashes due to stack overflow The function executes normally The recursion stops after 100 calls 45 / 100Which data type is used to store a single character in C? char string text character 46 / 100Which of the following is used to read input from the user in C? printf scanf getchar print 47 / 100What is a pointer in C? A variable that stores the address of another variable A function that returns memory size A keyword used to store addresses A data type 48 / 100Which operator is used to get the address of a variable? * & # @ 49 / 100Which statement is true about an enum? Enum constants can have floating-point values Enum constants must be unique Enum variables can store any integer value, not just the defined constants Enum constants can be repeated within the same enum 50 / 100What is the index of the first element in an array? 1 0 -1 Depends on the array size 51 / 100What is the correct way to declare and initialize a structure variable? MyStruct s = {10, 3.5}; struct s = {10, 3.5}; struct MyStruct s = {10, 3.5}; s = {10, 3.5}; 52 / 100Which of the following is a correct function prototype? int sum(a, b); int sum(int a, int b); sum(int a, int b); sum(a, b); 53 / 100What will be the output of this program? Compilation error 1 2 4 5 3 4 5 1 2 3 4 5 54 / 100Which of the following is the assignment operator in C? = += == != 55 / 100How do you access structure members in C? Using & operator Using . operator Using -> operator Using * operator 56 / 100What is the purpose of the break statement? To exit a loop or switch statement To jump to a labeled statement To skip the current iteration of a loop To return a value from a function 57 / 100What will be the output of this code? 2 3 Compilation error 1 1 2 3 58 / 100Can an array size be changed after declaration in C? Yes, using the realloc function Yes, using resize function No, array size is fixed Yes, by assigning a new array 59 / 100What is the difference between void and int functions? void functions cannot have parameters int functions cannot use printf() int functions run faster than void functions void functions do not return a value, while int functions return an integer 60 / 100What is the difference between while and do-while loops? No difference Both a & b do-while loop executes at least once, while may not execute at all while loop checks the condition first, do-while checks it last 61 / 100What is the main difference between break and continue? break and continue are the same break can only be used in switch, continue can only be used in loops break stops loop execution, while continue skips an iteration continue stops loop execution, while break skips an iteration 62 / 100What is the purpose of the return 0; statement in the main() function? It is used to return a value to printf It indicates successful program termination It is used to take input from the user It is required in every C program 63 / 100What does continue do in a while loop? Skips the remaining statements of the current iteration and continues with the next iteration Exits the loop Causes an infinite loop Jumps to another function 64 / 100What is a function prototype in C? A function definition A function that doesn't return any value A function declaration before its actual definition A function with no parameters 65 / 100What is the main advantage of recursion? It prevents stack overflow It always runs faster than loops It makes code shorter and easier to understand It reduces memory usage 66 / 100Which operator is used to access union members? * & . -> 67 / 100What is an enumeration (enum) in C? A pointer to an integer array A user-defined data type consisting of named integer constants A data type that stores multiple values of different types A type of structure that holds functions 68 / 100How do you dynamically allocate memory in C? malloc(10 * sizeof(int)) malloc(10) alloc(10) memory(10) 69 / 100How do you find the number of elements in an array in C? sizeof(arr) / sizeof(arr[0]) count(arr) length(arr) size(arr) 70 / 100What is the size of an int variable in C (typically on a 32-bit system)? 4 bytes 2 bytes 8 bytes 1 byte 71 / 100Can the conditional expression in an if statement be non-integer values? Only boolean values are allowed Only float values are allowed No, only integers are allowed Yes, it can be any non-zero value 72 / 100What is the purpose of typedef in structures? To allocate memory dynamically To create an alias for an existing function To simplify the declaration of structure variables To prevent modification of structure members 73 / 100What will be the output of the following program? 1 2 3 4 1 2 1 2 3 4 5 1 2 3 74 / 100Which of the following statements about recursion is false? Recursion is faster than iteration in all cases Recursion always uses more memory than iteration Every recursion must have a base case Recursion always uses more memory than iteration 75 / 100Which operator is used for bitwise XOR? ^ ~ & | 76 / 100What is the purpose of typedef with unions? To improve execution speed To create an alias for the union type To allocate memory dynamically To prevent modification of union members 77 / 100What is the purpose of the else if statement? It allows checking multiple conditions It runs when the if condition is false It runs only if the else statement runs It terminates the program if no condition is true 78 / 100How are multi-dimensional arrays stored in memory? Column-major order (column-wise) Random order Row-major order (row-wise) Not stored in memory 79 / 100What will be the default value of GREEN in the following code?enum Color { RED, GREEN, BLUE }; It depends on user input 0 1 2 80 / 100How do you declare a union variable in C? struct Example obj; data union Example obj; Example obj; union Example obj; 81 / 100How do you pass an argument by reference in C? Using a pointer (*) Using an array Using a return statement Using an ampersand (&) 82 / 100What is the ASCII value of '0'? 48 49 0 -48 83 / 100Which of the following is a logical operator in C? All of the above ! || && 84 / 100What happens if two enumeration constants have the same value? Runtime error Causes undefined behavior Allowed without any error Compilation error 85 / 100What is the output of the following code? 20 10 15 5 86 / 100What is the best practice regarding goto in C? Avoid using it as much as possible It is required in all C programs Use it frequently for better readability Use it only in switch statements 87 / 100What will be the output of the following code? 5 Compilation error 10 15 88 / 100How do you declare a pointer to a structure? Student ptr; ptr struct Student; struct Student* ptr; Student* ptr; 89 / 100What is the size of an enum in C? 8 bytes Depends on the number of members Same as a char (1 byte) Same as an int (usually 4 bytes) 90 / 100How do you access structure members using a pointer? ptr:member ptr.member ptr(member) ptr->member 91 / 100Which of the following is NOT a jump statement in C? switch break continue return 92 / 100Which statement is true about return? It can only be used in main() It stops execution but does not return control to the calling function It is used to return a value from a function It can be used in loops to skip an iteration 93 / 100What will be the output of the following code? Compilation error 2.000000 2.500000 2 94 / 100Which of the following correctly initializes an array? int arr[] = {1, 2, 3}; All of the above int arr[3] = {1, 2, 3}; int arr[3] = {1}; 95 / 100How do you define a structure in C? struct MyStruct ( int a; float b; ); struct { int a; float b; } structure MyStruct { int a; float b; } struct MyStruct { int a; float b; }; 96 / 100Which of the following is NOT a type of loop in C? while loop for loop foreach loop do-while loop 97 / 100In which of the following can break be used Loops only switch only Functions only Both loops and switch 98 / 100Which statement is used to exit a switch case? stop break return exit 99 / 100How do you define an enumeration in C? enum Color { RED, GREEN, BLUE }; enumeration Color { RED, GREEN, BLUE }; enum { RED, GREEN, BLUE } Color; define enum Color { RED, GREEN, BLUE }; 100 / 100What happens if the condition in a loop is always true? The loop will exit after 10 iterations The compiler will throw an error The program will crash The loop will run indefinitely (infinite loop) Your score isThe average score is 38% 0% Restart quiz