Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Which function is the mandatory entry point of every C program where execution begins?
Not quite. Try another option.
Answer: main()
Execution of a C program always begins from the main() function, which is compulsory in every program.
Question 2 of 60 · C program structure · Easy
Which section of a C program is used to include header files like #include <stdio.h>?
Not quite. Try another option.
Answer: Preprocessor directive section
Lines beginning with # such as #include are preprocessor directives, processed before actual compilation.
Question 3 of 60 · character set · Easy
Which of the following is NOT part of the C character set?
Not quite. Try another option.
Answer: Greek letter
The C character set includes letters (A-Z, a-z), digits (0-9), special symbols, and white spaces. Greek letters are not part of it.
Question 4 of 60 · identifiers and keywords · Easy
Which of the following is a valid identifier in C?
Not quite. Try another option.
Answer: total_marks
An identifier can contain letters, digits, and underscores, but must not start with a digit, be a keyword, or contain spaces.
Question 5 of 60 · identifiers and keywords · Easy
How many keywords are defined in standard (ANSI) C?
Not quite. Try another option.
Answer: 32
ANSI C defines 32 reserved keywords such as int, float, return, and while.
Question 6 of 60 · constants and variables · Easy
Which keyword is used to declare a constant whose value cannot be changed during program execution?
Not quite. Try another option.
Answer: const
The const qualifier makes a variable read-only, so its value cannot be modified after initialization.
Question 7 of 60 · constants and variables · Easy
What is a variable in C?
Not quite. Try another option.
Answer: A named memory location whose value can change during program execution
A variable is a named storage location in memory whose value can be modified while the program runs.
Question 8 of 60 · data types · Easy
Which data type is used to store a single character in C?
Not quite. Try another option.
Answer: char
The char data type stores a single character and typically occupies 1 byte of memory.
Question 9 of 60 · data types · Easy
Which of the following is used to store numbers with a decimal point?
Not quite. Try another option.
Answer: float
The float data type stores real numbers containing fractional (decimal) parts.
Question 10 of 60 · unformatted and formatted i/o functions · Easy
Which format specifier is used to print an integer using printf()?
Not quite. Try another option.
Answer: %d
The %d format specifier is used to read and print integer values in printf() and scanf().
Question 11 of 60 · unformatted and formatted i/o functions · Easy
Which function is used to read a single character from the keyboard?
Not quite. Try another option.
Answer: getchar()
getchar() reads a single character from standard input, while putchar() displays a single character.
Question 12 of 60 · unformatted and formatted i/o functions · Easy
Which function is used to display a string on the screen and automatically moves the cursor to a new line?
Not quite. Try another option.
Answer: puts()
puts() outputs a string to the screen and appends a newline character automatically.
Question 13 of 60 · unformatted and formatted i/o functions · Easy
In scanf("%d", &n);, what does the & symbol represent?
Not quite. Try another option.
Answer: Address of the variable n
& is the address-of operator; scanf() needs the memory address of a variable to store the input value there.
Question 14 of 60 · expressions · Easy
What is the result of the expression 5 + 3 * 2 in C?
Not quite. Try another option.
Answer: 11
Multiplication has higher precedence than addition, so 3 * 2 = 6 is evaluated first, giving 5 + 6 = 11.
Question 15 of 60 · arithmetic operators · Easy
Which arithmetic operator returns the remainder of a division?
Not quite. Try another option.
Answer: %
The modulus operator % gives the remainder after integer division, e.g. 7 % 3 = 1.
Question 16 of 60 · unary operator · Easy
What does the ++ operator do in C?
Not quite. Try another option.
Answer: Increases the value of a variable by 1
The increment operator ++ is a unary operator that adds 1 to the value of its operand.
Question 17 of 60 · relational operator · Easy
Which operator is used to check whether two values are equal in C?
Not quite. Try another option.
Answer: ==
== is the equality relational operator, while a single = is the assignment operator.
Question 18 of 60 · logical operator · Easy
Which of the following is the logical AND operator in C?
Not quite. Try another option.
Answer: &&
&& is the logical AND operator, returning true only when both operands are true. & is the bitwise AND operator.
Question 19 of 60 · assignment and conditional operator · Easy
What is the value of x after int x = (5 > 3) ? 10 : 20;?
Not quite. Try another option.
Answer: 10
The conditional operator ?: evaluates the condition 5 > 3 as true, so x gets the value 10.
Question 20 of 60 · bitwise operators · Easy
Which of the following is the bitwise OR operator in C?
Not quite. Try another option.
Answer: |
The single | symbol is the bitwise OR operator that operates on individual bits, while || is the logical OR operator.
Question 21 of 60 · C program structure · Medium
In a standard C program, which section is used to include header files and define macros before the main() function?
Not quite. Try another option.
Answer: Preprocessor directive section
Lines like #include and #define belong to the preprocessor directive section, which is processed before compilation and typically appears at the top of the program.
Question 22 of 60 · character set · Medium
Which of the following is NOT part of the valid C character set?
Not quite. Try another option.
Answer: @ used as an operator
C has no @ operator. Although @ may appear inside strings, it is not a valid operator or token in the C language, unlike #, %, digits, and whitespace.
Question 23 of 60 · identifiers and keywords · Medium
Which of the following is a valid C identifier?
Not quite. Try another option.
Answer: _total_2
Identifiers must begin with a letter or underscore and contain only letters, digits, and underscores. 2ndValue starts with a digit, float is a keyword, and my-var contains a hyphen.
Question 24 of 60 · identifiers and keywords · Medium
How many keywords are reserved in standard ANSI C (C89/C90)?
Not quite. Try another option.
Answer: 32
ANSI C (C89/C90) defines 32 reserved keywords such as int, for, while, and return. These cannot be used as identifiers.
Question 25 of 60 · constants and variables · Medium
What is the output of the following code?
c
const int x = 10;
x = 20;
printf("%d", x);
Not quite. Try another option.
Answer: Compilation error
A variable declared with const cannot be reassigned. Attempting x = 20; produces a compile-time error (assignment of read-only variable).
Question 26 of 60 · data types · Medium
On a typical 32-bit system, what is the size (in bytes) of a double variable?
Not quite. Try another option.
Answer: 8
A double typically occupies 8 bytes and offers greater precision than a float, which usually occupies 4 bytes.
Question 27 of 60 · data types · Medium
What is the output of the following code?
c
char c = 'A';
printf("%d", c);
Not quite. Try another option.
Answer: 65
Using %d prints the integer ASCII value of the character. The ASCII code for uppercase 'A' is 65.
Question 28 of 60 · unformatted and formatted i/o functions- printf(), scanf(), puts(), gets(), getchar(), putchar() · Medium
Which function reads a full line of text including spaces until a newline is encountered?
Not quite. Try another option.
Answer: gets()
gets() reads an entire line including spaces until newline. scanf("%s") stops at whitespace, getchar() reads one character, and putchar() is for output.
Question 29 of 60 · unformatted and formatted i/o functions- printf(), scanf(), puts(), gets(), getchar(), putchar() · Medium
What does printf("%d", printf("AB")); output?
Not quite. Try another option.
Answer: AB2
printf returns the number of characters printed. The inner call prints AB and returns 2, which the outer printf then prints, giving AB2.
Question 30 of 60 · unformatted and formatted i/o functions- printf(), scanf(), puts(), gets(), getchar(), putchar() · Medium
In scanf, why is the & operator used before variable names for basic types like int?
Not quite. Try another option.
Answer: To pass the address so scanf can store the value
scanf needs the memory address of a variable to write the input value into it. The & (address-of) operator supplies that address.
Question 31 of 60 · expressions · Medium
What is the value of the expression 5 + 3 * 2 - 8 / 4?
Not quite. Try another option.
Answer: 9
Multiplication and division bind tighter than addition and subtraction: 3*2=6 and 8/4=2, giving 5 + 6 - 2 = 9.
Question 32 of 60 · arithmetic operators · Medium
What is the output of the following code?
c
printf("%d", 17 % 5);
Not quite. Try another option.
Answer: 2
The modulus operator % returns the remainder of integer division. remainder , so the result is 2.
Question 33 of 60 · unary operator · Medium
What is the output of the following code?
c
int a = 5;
int b = a++ + ++a;
printf("%d", b);
Not quite. Try another option.
Answer: 12
a++ uses 5 then makes a=6; ++a first makes a=7 and uses 7. So b = 5 + 7 = 12.
Question 34 of 60 · relational operator · Medium
What is the value of the expression (10 > 5) > 3 in C?
Not quite. Try another option.
Answer: 0
10 > 5 evaluates to 1. Then 1 > 3 is false, so the whole expression evaluates to 0.
Question 35 of 60 · logical operator · Medium
In the expression a && b, if a evaluates to 0, what happens to b?
Not quite. Try another option.
Answer: b is not evaluated due to short-circuiting
The && operator short-circuits: if the left operand is 0 (false), the result is already 0, so the right operand b is never evaluated.
Question 36 of 60 · assignment and conditional operator · Medium
What is the value of max after this code runs?
c
int a = 8, b = 12;
int max = (a > b) ? a : b;
Not quite. Try another option.
Answer: 12
The conditional operator returns the second value if the condition is true and the third if false. Since a > b is false, max gets b, which is 12.
Question 37 of 60 · assignment and conditional operator · Medium
After executing int x = 10; x += x -= 5;, what is the value of x?
Not quite. Try another option.
Answer: 10
First x -= 5 sets x to 5 and yields 5. Then x += 5 evaluates using the current value 5, giving 5 + 5 = 10.
Question 38 of 60 · bitwise operators · Medium
What is the result of 12 & 10 in C?
Not quite. Try another option.
Answer: 8
In binary, and . Bitwise AND keeps bits set in both: .
Question 39 of 60 · bitwise operators · Medium
What is the value of 5 << 2?
Not quite. Try another option.
Answer: 20
Left shifting by n multiplies by . So .
Question 40 of 60 · type conversion and type modifiers · Medium
What is the output of the following code?
c
printf("%d", (int)(7.0 / 2));
Not quite. Try another option.
Answer: 3
7.0 / 2 performs floating-point division giving 3.5. Casting to int truncates the fractional part, resulting in 3.
Question 41 of 60 · bitwise operators · Hard
Assuming 32-bit int, what is the value of the expression ~5 & 0xFF when printed with %d?
Not quite. Try another option.
Answer: 250
~5 produces 0xFFFFFFFA (bitwise complement, value -6). Masking with 0xFF keeps only the low 8 bits: 0xFA = 250. The mask discards the sign-extended upper bits, so the result is a positive 250.
Question 42 of 60 · arithmetic operators · Hard
In C, what is the result of -7 % 3 and 7 % -3 respectively (C99 and later)?
Not quite. Try another option.
Answer: -1 and 1
Since C99, integer division truncates toward zero, so the % result takes the sign of the dividend (left operand). -7 % 3 gives -1, and 7 % -3 gives 1. This satisfies the identity (a/b)*b + a%b == a.
Question 43 of 60 · unary operator · Hard
Given int i = 5;, what value is assigned in int j = i++ + ++i; and what is i afterward? (Common compiler behavior)
Not quite. Try another option.
Answer: j is unspecified due to undefined behavior; result is not guaranteed
The variable i is modified twice between sequence points without an intervening sequence point (i++ and ++i in the same expression). This is undefined behavior in C, so no specific value can be relied upon regardless of what a particular compiler outputs.
Question 44 of 60 · type conversion and type modifiers · Hard
What does printf("%d\n", (int)(3.99 + 2.99)); print, and why?
Not quite. Try another option.
Answer: 6
The addition happens in double: 3.99 + 2.99 = 6.98. The cast to int truncates the fractional part toward zero, giving 6. Truncation is not rounding, so 6.98 becomes 6, not 7.
Question 45 of 60 · logical operator · Hard
For int a = 0, b = 5; int r = a++ && ++b;, what are the final values of r, a, and b?
Not quite. Try another option.
Answer: r = 0, a = 1, b = 5
a++ evaluates to 0 (post-increment yields old value), which is false. Due to short-circuit evaluation of &&, the right operand ++b is never evaluated, so b stays 5. But a was already incremented to 1. The overall result is 0.
Question 46 of 60 · unformatted and formatted i/o functions- printf(), scanf(), puts(), gets(), getchar(), putchar() · Hard
Given input 12 34 (with a space), what does this code print?
c
int a, b;
scanf("%d%d", &a, &b);
printf("%d", a + b);
Not quite. Try another option.
Answer: 46
%d conversion in scanf automatically skips leading whitespace (including the space) before reading each integer. So a = 12 and b = 34, and a + b = 46.
Question 47 of 60 · assignment and conditional operator · Hard
What is the value of x after int x = 4; x = (x > 2) ? (x < 8 ? x * 2 : x / 2) : x + 1;?
Not quite. Try another option.
Answer: 8
Outer condition x > 2 (4 > 2) is true, so the middle branch executes. Inner condition x < 8 (4 < 8) is true, so x * 2 = 8 is assigned. Nested conditional operators associate right, evaluated inside-out here.
Question 48 of 60 · data types · Hard
On a system with 8-bit char, what does unsigned char c = 300; printf("%d", c); print?
Not quite. Try another option.
Answer: 44
An unsigned char holds values 0 to 255. Assigning 300 wraps modulo 256: 300 - 256 = 44. The value stored is 44, printed as 44.
Question 49 of 60 · bitwise operators · Hard
What is the output of printf("%d", 1 << 3 | 1 << 1);?
Not quite. Try another option.
Answer: 10
<< has higher precedence than |. So it computes (1 << 3) | (1 << 1) = 8 | 2 = 10 (binary 1010). The shift operators bind tighter than the bitwise OR.
Question 50 of 60 · type conversion and type modifiers · Hard
What does the following print on a typical system?
c
unsigned int u = 10;
int i = -1;
if (i < u) printf("less"); else printf("not less");
Not quite. Try another option.
Answer: not less
In the comparison, the int-1 is converted to unsigned int due to the usual arithmetic conversions. -1 becomes a very large value (UINT_MAX), which is greater than 10. So i < u is false and it prints not less.
Question 51 of 60 · identifiers and keywords · Hard
Which of the following is a valid C identifier?
Not quite. Try another option.
Answer: _count2
Identifiers must begin with a letter or underscore and contain only letters, digits, and underscores. 2count starts with a digit, double is a reserved keyword, and my-var contains a hyphen. Only _count2 is valid.
Question 52 of 60 · expressions · Hard
What is the value of the expression 5 + 3 * 2 % 4 - 1?
Not quite. Try another option.
Answer: 6
* and % have equal precedence and associate left to right: 3 * 2 = 6, then 6 % 4 = 2. Then 5 + 2 - 1 = 6. Multiplication and modulo bind tighter than addition and subtraction.
Question 53 of 60 · constants and variables · Hard
What is the output of printf("%d", 010 + 0x10);?
Not quite. Try another option.
Answer: 24
010 is an octal constant (leading zero) equal to decimal 8. 0x10 is a hexadecimal constant equal to decimal 16. Their sum is 8 + 16 = 24.
Question 54 of 60 · unformatted and formatted i/o functions- printf(), scanf(), puts(), gets(), getchar(), putchar() · Hard
What does printf("%d", printf("abc")); output?
Not quite. Try another option.
Answer: abc3
The inner printf("abc") runs first, printing abc and returning the number of characters written, which is 3. The outer printf then prints that return value 3. So the output is abc3.
Question 55 of 60 · relational operator · Hard
What does printf("%d", 3 < 2 < 1); print?
Not quite. Try another option.
Answer: 1
< is left-associative, so this parses as (3 < 2) < 1. 3 < 2 is 0 (false). Then 0 < 1 is 1 (true). The result is 1, a common trap when chaining relational operators.
Question 56 of 60 · bitwise operators · Hard
Which expression correctly toggles (flips) the 3rd bit (bit index 2, value 4) of an integer n while leaving other bits unchanged?
Not quite. Try another option.
Answer: n ^ (1 << 2)
XOR with a mask flips exactly the masked bits. n | mask only sets the bit, n & ~mask only clears it, and n & mask isolates it. Only n ^ (1 << 2) toggles bit 2 while preserving the rest.
Question 57 of 60 · type conversion and type modifiers · Hard
What is printed by float f = 0.1f; printf("%d", f == 0.1);? (Assume IEEE-754)
Not quite. Try another option.
Answer: 0
0.1f is a float rounded to single precision, while 0.1 is a double. In the comparison, f is promoted to double, but its value differs from the double representation of 0.1 because of the earlier single-precision rounding. So the comparison is false, printing 0.
Question 58 of 60 · unary operator · Hard
Given int a = 10; int b = -a++;, what are the values of b and a afterward?
Not quite. Try another option.
Answer: b = -10, a = 11
Postfix ++ has higher precedence than unary minus but yields the old value 10. So -a++ is -(10) = -10 assigned to b, while a is incremented to 11 as a side effect.
Question 59 of 60 · expressions · Hard
What is the output of int x = 5; printf("%d %d", x != 0, !x);?
Not quite. Try another option.
Answer: 1 0
x != 0 is true since 5 != 0, yielding 1. The logical NOT !x treats any nonzero value as true, so !5 is 0. Output is 1 0.
Question 60 of 60 · data types · Hard
On a system where int is 4 bytes, what does printf("%d", sizeof('A')); most likely print in a C program (not C++)?
Not quite. Try another option.
Answer: 4
In C, a character constant like 'A' has type int, not char. Therefore sizeof('A') equals sizeof(int), which is 4 on this system. This differs from C++, where character constants are of type char (size 1).
That's unit 2
Answer a few questions and your score shows up here.
Nearly through. Did unit 2 of CAP1008 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 2 of CAP1008 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.