




















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A beginner-friendly programming exam focused on basic coding logic, syntax, functions, loops, arrays, debugging, and simple algorithms. It covers popular languages such as Python, Java, and C, emphasizing computational thinking and fundamental programming problem-solving skills.
Typology: Exams
1 / 92
This page cannot be seen from the preview
Don't miss anything!





















































































Question 1. Which phase of the C compilation process translates source code into machine code? A) Preprocessing B) Assembling C) Linking D) Compiling Answer: D Explanation: The compiler parses the source, performs syntax analysis, optimization, and generates object code (machine code). Question 2. What is the purpose of a header file in a C program? A) To store executable code B) To declare functions, macros, and types used by multiple source files C) To allocate dynamic memory D) To define the main entry point Answer: B Explanation: Header files contain declarations that can be shared across translation units, enabling code reuse and modularity. Question 3. Which of the following is a correct statement about C’s portability? A) C programs run without modification on any operating system because the language is interpreted. B) The ANSI C standard defines a common core language, allowing source code to be compiled on many platforms. C) Portability is achieved by using only Microsoft‑specific extensions. D) Portability requires embedding assembly code for each target CPU. Answer: B
Explanation: ANSI C standardizes syntax and library functions, making source code portable across conforming compilers. Question 4. Which of the following literals is of type double? A) 3.14f B) 2 C) 6.022e23 D) 'a' Answer: C Explanation: Scientific notation without an f suffix defaults to double. Question 5. What is the result of the expression (int)3.9 + (float)2? A) 5. B) 5 C) 6 D) 6. Answer: B Explanation: (int)3.9 truncates to 3, (float)2 becomes 2.0; the addition yields 5.0, which is then implicitly converted to int for assignment, producing 5. Question 6. Which printf format specifier prints a single character? A) %c B) %s C) %d
C) At the end of the statement block D) It depends on compiler flags Answer: B Explanation: Prefix increment increments the variable before its value participates in the surrounding expression. Question 10. Which logical operator implements short‑circuit evaluation? A) & B) | C) && D) ^ Answer: C Explanation: && evaluates the right operand only if the left operand is true, providing short‑circuit behavior. Question 11. What does the bitwise operator ~ do? A) Shifts bits left B) Shifts bits right C) Performs bitwise NOT (complement) D) Performs bitwise XOR with 1 Answer: C Explanation: ~ flips each bit, producing the one's complement of the operand. Question 12. Which of the following statements correctly declares a variable that can hold a large positive integer?
A) int x; B) unsigned long x; C) short int x; D) signed char x; Answer: B Explanation: unsigned long provides a larger range for non‑negative integers than int or short. Question 13. What is the output of the following code?
int a = 5, b = 2; printf("%d", a / b); A) 2 B) 2. C) 3 D) 0 Answer: A Explanation: Integer division truncates the fractional part; 5/2 yields 2. Question 14. Which relational operator tests for “greater than or equal to”? A) > B) < C) >= D) !=
C) Exits the program. D) Jumps to the beginning of the loop. Answer: B Explanation: break exits the innermost loop immediately. Question 18. Which statement correctly declares a two‑dimensional array of integers with 3 rows and 4 columns? A) int arr[3][4]; B) int arr[4][3]; C) int arr[3,4]; D) int arr[3*4]; Answer: A Explanation: int arr[3][4]; creates a matrix of 3 rows and 4 columns. Question 19. Given int a[5] = {0,1,2,3,4};, what is the value of *(a + 3)? A) 2 B) 3 C) 4 D) Undefined Answer: B Explanation: a points to the first element; adding 3 moves to a[3], which holds 3. Question 20. Which operator is used to obtain the address of a variable? A) *
&#@Answer: B Explanation: The address‑of operator & yields the memory address of its operand. Question 21. What is the result of the expression *(ptr++) where ptr is of type int *? A) The value pointed to by ptr before incrementing, then ptr is incremented. B) The value pointed to after incrementing ptr. C) Undefined behavior. D) Compilation error. Answer: A Explanation: Post‑increment returns the original pointer value for dereferencing, then increments the pointer. Question 22. Which function allocates memory for an array of 10 double elements? A) malloc(10 * sizeof(double)) B) calloc(10, sizeof(double)) C) realloc(10, sizeof(double)) D) Both A and B are correct. Answer: D Explanation: Both malloc (with size calculation) and calloc (which also zero‑initializes) can allocate the required memory.
Explanation: strlen counts characters before the terminating null byte; “Hello” has 5 characters. Question 26. Which of the following is the correct prototype for a function that returns an int and takes two float arguments? A) int func(float a, float b); B) float func(int a, int b); C) void func(float a, float b); D) int func(int a, int b); Answer: A Explanation: The prototype matches the described return type and parameter list. Question 27. In C, which storage class gives a variable internal linkage (visible only within its translation unit)? A) extern B) static C) auto D) register Answer: B Explanation: static at file scope restricts visibility to the defining source file. Question 28. What is the scope of a variable declared inside a function body? A) Global B) File C) Block (local)
D) External Answer: C Explanation: Variables defined inside a block are local to that block and cease to exist after the block ends. Question 29. Which of the following statements about the void return type is true? A) A function returning void must return a value. B) void can be used as a parameter type to indicate no arguments. C) void variables can be declared. D) void functions cannot be called. Answer: B Explanation: Declaring a function as void func(void) indicates it takes no arguments. Question 30. Which operator is used to combine two conditions such that both must be true? A) || B) && C) & D) | Answer: B Explanation: Logical AND (&&) evaluates to true only if both operands are true. Question 31. What is the result of the expression 0 && (printf("Hello"))? A) Prints “Hello” and evaluates to 0 B) Prints “Hello” and evaluates to 1
A) const int *p means the pointer p cannot be changed. B) int * const p means the data pointed to cannot be changed. C) const int *p means the data pointed to cannot be modified through p. D) const can only be applied to global variables. Answer: C Explanation: const int *p makes the pointed‑to value read‑only via p. Question 35. Which format specifier should be used to print a long long int in decimal form? A) %lld B) %ld C) %d D) %ll Answer: A Explanation: %lld matches the long long int type. Question 36. What does the expression sizeof(char) evaluate to on any conforming C implementation? A) 0 B) 1 C) 2 D) Implementation‑defined Answer: B Explanation: By definition, sizeof(char) is always 1 byte.
Question 37. Which statement about the enum type is true? A) Enumerators are of type int by default. B) An enum can contain floating‑point values. C) enum values are automatically assigned the character 'a'. D) enum cannot be used in switch statements. Answer: A Explanation: Enumerators are integral constants, typically of type int. Question 38. Which of the following is a valid way to initialize a structure variable Point p = {3,4}; assuming struct Point {int x; int y;};? A) struct Point p = {3,4}; B) struct Point p = (3,4); C) struct Point p = {x:3, y:4}; D) struct Point p = { [0]=3, [1]=4 }; Answer: A Explanation: Braced initializer lists initialize members in order of declaration. Question 39. What is the effect of the register storage class specifier? A) Forces the variable to be stored in a CPU register if possible. B) Makes the variable globally accessible. C) Prevents the variable from being initialized. D) Allows the variable to be accessed via pointer arithmetic. Answer: A
C) The variable is allocated on the heap. D) The variable must be initialized to zero. Answer: A Explanation: A static local variable has static storage duration, preserving its value across calls. Question 43. What does the #include <stdio.h> directive do? A) Inserts the contents of the file stdio.h located in the current directory. B) Links the standard I/O library at compile time. C) Tells the preprocessor to search the system include directories for stdio.h and insert its contents. D) Declares the printf function without including any header. Answer: C Explanation: Angle brackets direct the preprocessor to look in implementation‑defined system include paths. Question 44. Which of the following statements about scanf is correct? A) %s reads a whitespace‑terminated string and automatically appends a null terminator. B) %c skips leading whitespace characters. C) The & operator is never needed when scanning into an array. D) scanf returns the number of characters read. Answer: A Explanation: %s reads a sequence of non‑whitespace characters and adds '\0'. Question 45. Which of the following expressions yields the same result as a & 0xFF for an unsigned integer a?
A) a % 256 B) a >> 8 C) a << 8 D) a ^ 0xFF Answer: A Explanation: Masking with 0xFF extracts the lowest 8 bits, equivalent to modulo 256 for non‑negative values. Question 46. What does the volatile qualifier indicate to the compiler? A) The variable will never change after initialization. B) The variable may be changed by external factors and must not be optimized away. C) The variable can be accessed only through pointers. D) The variable is stored in read‑only memory. Answer: B Explanation: volatile tells the compiler that the value can change unexpectedly, preventing certain optimizations. Question 47. Which of the following statements correctly declares an array of 5 pointers to char? A) char *arr[5]; B) char arr[5]*; C) char arr* [5]; D) char (*arr)[5]; Answer: A Explanation: char *arr[5]; is an array of 5 elements, each of which is a pointer to char.
0 1 20 21 20 1Answer: B Explanation: When i is 1, continue skips the printf; thus only 0 and 2 are printed. Question 51. Which of the following correctly declares a function that takes a variable number of arguments? A) int sum(int count, ...); B) int sum(...); C) int sum(int count); D) int sum(int, ...); Answer: A Explanation: The ellipsis (...) after a fixed parameter list indicates a variadic function. Question 52. In the context of printf, what does the precision specifier .3 in %6.3f control? A) Minimum field width B) Number of digits after the decimal point C) Total number of printed characters D) Alignment of the output Answer: B Explanation: The precision for floating‑point (%f) defines digits after the decimal point.
Question 53. Which of the following statements about union is correct? A) All members share the same memory location, and the size equals the largest member. B) Each member has its own distinct memory area. C) Unions can only contain integer types. D) Accessing a member other than the last stored value is undefined behavior. Answer: A Explanation: A union overlays its members; its size is the size of its largest member. Question 54. What does the expression ptr = NULL; accomplish? A) Frees the memory pointed to by ptr. B) Sets the pointer to a null pointer constant, indicating it points to nothing. C) Causes a segmentation fault. D) Allocates memory for ptr. Answer: B Explanation: Assigning NULL makes the pointer a null pointer, a safe sentinel value. Question 55. Which of the following is true about the goto statement? A) It can jump out of a function. B) It can only jump forward to a label. C) It transfers control to a labeled statement within the same function. D) It is prohibited by the C standard. Answer: C Explanation: goto may jump to any label inside the same function, forward or backward.