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