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