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