PYQ - 2 | C Programming Previous Year Questions (PYQ) PDF | MCQs & Solutions| Comprehensive C Programming Quiz with Detailed Explanations
A quiz covering C programming fundamentals including format specifiers, comments, storage classes, arrays, strings, identifiers, unions, and function returns with clear answers and explanations.
PYQ - 2 | C Programming Previous Year Questions (PYQ) PDF | MCQs & Solutions| Comprehensive C Programming Quiz with Detailed Explanations
2.
Q.1. What isthe output of the following code?
printf("%.2f", 3.14159);
A. 3
B. 3.14 ✅
C. 3.142
D. None
❖ The %.2f format specifier treats your value as a floating-point number and
restricts the output to exactly two digits after the decimal point. Because the third
decimal digit of 3.14159 is 1 (which is less than 5), the number rounds down,
resulting in 3.14.
★ Computer Science- 2023
3.
Q.2. How doyou write a single-line comment in C ?
A. /* This is a comment */
B. # This is Comments
C. // This is Comments
D. – – This is Comments
❖ To write a single-line comment in C,utilizing two forward slashes (//)
serves as the standard syntax for creating a single-line comment.
★ ISRO - 2015
4.
Q.3. Which storageclass provides the shortest access time?
A. Auto
B. Extern
C. Static
D. Register✅
❖ Register memory provides the shortest access time.
❖ Located directly within the CPU, registers are built to hold the exact data and instructions the
processor is immediately using.
❖ Because they don't have to communicate with the rest of the computer's components, access
times are nearly instantaneous (often within a single clock cycle).
★ Computer Science - 2024
5.
Q.4. Which ofthe following correctly declares an array ?
A. Int Weeks[20];✅
B. Int Weeks;
C. Int Weeks{20};
D. Array Weeks[20];
❖ Languages like C or C++, a standard array declaration generally follows the
syntax: data_type array_name[array_size];
❖ for example, int myArray[10];
★ ISRO - 2008
6.
Q.5. What willbe the output of the following C code?
printf("%d", strlen("hello"));
A. 4
B. 5✅
C. 6
D. 7
❖ String Length: The strlen() function counts the number of characters in a string up to,
but not including, the null-terminating character (0).
❖ Character Count: The string "hello" contains exactly 5 characters: h, e, l, l, and o.
❖ Printing: The printf function uses the %d format specifier to display this length as an
integer value.
★ Computer Science - 2025
7.
Q.6. _______ referto the names of functions, variables, arrays,
classes etc.
A. Identifiers ✅
B. Manipulators
C. Operators
D. Punctuators
The names given to program elements like variables, functions, arrays, and classes are called identifiers.
Rules for Creating Identifiers
● Character sets: They must consist only of letters, digits, and underscores (_).
● Starting character: They must begin with a letter or an underscore, never a number.
● No spaces: White spaces or special characters are strictly prohibited within the name.
● Keywords: Reserved language keywords (like int, if, or class) cannot be used as identifiers.
★ CDAC CCAT - 2017
8.
Q.7. What isthe default storage class for a global variable ?
A. Auto
B. Extern ✅
C. Static
D. Register
❖ The default storage class for a global variable is extern (external). Variables declared globally
have a static duration and are allocated in the data segment of memory. By default, they are
visible to all files in the program and automatically initialized to 0.
❖ If a global variable is declared but not defined, C treats it as an `extern` variable by default. `extern`
variables are accessible throughout the entire program, making them global in nature.
★ Computer Science - 2023
9.
Q.8. Size ofa union is determined by the size of the _____ ?
A. First Member of the Union
B. Last Member of the Union
C. Biggest Member of the Union ✅
D. All Of These
❖ The size of a union is determined by the size of its largest member.
❖ Because all members in a union share the exact same memory space, the compiler
allocates enough memory to accommodate the largest data type, plus any
necessary padding for byte alignment
★ TCS - 2026
10.
Q.9. What isthe purpose of the '%s' format specifier in C ?
A. To Print the single character
B. To print an Integer
C. To print a String ✅
D. To print the floating point number
❖ In C, the %s format specifier is used as a placeholder to read or print a
string (a sequence of characters).
❖ It functions by interacting with a pointer to the first character of a null-terminated
(0) character array
★ Computer Science - 2023
11.
Q.10. The valueobtained in the function is given back to main by
using __________ keyword. ?
A.Static
B. New
C. Non- Volatile
D. Return ✅
❖ In programming, the return keyword is used to send a value back from a function to the
calling code (like main).
❖ It terminates the function execution and passes control along with any specified value.
★ UP LT - 2026