Karnataka KSEAB SSLC JTS Programming in ANSI C study materials
Karnataka KSEAB SSLC JTS Programming in ANSI C study resources

Karnataka KSEAB SSLC JTS Programming in ANSI C practice questions

One question at a time. Build your Karnataka KSEAB SSLC JTS Programming in ANSI C understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

In ANSI C, which of the following character sequences legally terminates every executable C source text file that contains statements?

  1. The keyword stop
  2. The single character newline Correct answer.
  3. The token END
  4. The two-character sequence \n

Explanation

A C source file is a sequence of characters ending with a newline character, and the translation phase that ends each line requires that final newline before preprocessing. There is no END token or stop keyword in C, and \n is an escape sequence used inside character or string literals, not a file terminator.

Question 2C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which of the following is a valid identifier in ANSI C?

  1. 2ndValue
  2. total_amount Correct answer.
  3. float
  4. my-var

Explanation

An identifier must begin with a letter or underscore and may then contain only letters, digits and underscores; total_amount satisfies all of these. Names beginning with a digit, containing a hyphen, or matching a keyword are all rejected by the compiler.

Question 3C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

How many keywords does ANSI C (C89/C90) define?

  1. 24
  2. 28
  3. 30
  4. 32 Correct answer.

Explanation

The original ANSI C standard specifies exactly 32 keywords, including auto, register, volatile, const, signed and enum. Later standards such as C99 added further keywords, but the ANSI C89 set is fixed at 32.

Question 4C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which statement correctly declares a variable of type double and initialises it to 2.5?

  1. double 2.5 = x;
  2. double x == 2.5;
  3. x double = 2.5;
  4. double x = 2.5; Correct answer.

Explanation

A declaration places the type specifier first, then the identifier, then an optional initialiser introduced by a single equals sign. The double equals sign is the equality operator and cannot appear in a declaration, and the order of type and name cannot be swapped.

Question 5C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

What is the type of the constant 0x1F in ANSI C?

  1. double
  2. unsigned int
  3. int Correct answer.
  4. char

Explanation

A hexadecimal integer constant with no suffix and a value that fits in int has type int. The 0x prefix merely selects base 16 for the digits; it does not change the type to unsigned or to a floating type.

Question 6C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which escape sequence represents a horizontal tab character in a C character constant?

  1. \b
  2. \t Correct answer.
  3. \0
  4. \n

Explanation

In C escape sequences, \t stands for the horizontal tab. The others denote newline, backspace and the null character respectively.

Question 7C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which pair of specifiers is used with the signed integer type modifiers in ANSI C?

  1. signed and unsigned Correct answer.
  2. long and short
  3. extern and static
  4. const and volatile

Explanation

signed and unsigned are the two sign specifiers that can be combined with the integer types char, short, int and long. The others are size modifiers, type qualifiers and storage-class specifiers respectively.

Question 8C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

A variable declared as char in ANSI C is guaranteed to occupy exactly how many bytes?

  1. 1 Correct answer.
  2. 2
  3. 4
  4. It depends on the compiler's word size

Explanation

The C standard defines the size of char as exactly one byte, and sizeof(char) is always 1. The number of bits in that byte is implementation-defined, but the byte count is fixed.

Question 9C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which of the following is a valid C character constant?

  1. 'ab'
  2. a
  3. "a"
  4. '\n' Correct answer.

Explanation

A character constant is one or more characters enclosed in single quotes; the escape sequence \n inside single quotes is a valid example. Double quotes create a string literal, and a bare letter is an identifier.

Question 10C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which statement about the const qualifier in ANSI C is correct?

  1. A const-qualified object cannot be modified after initialisation through that name. Correct answer.
  2. A const variable can never be used as an array size.
  3. A const variable is automatically placed in read-only memory by every compiler.
  4. A const variable must be initialised at run time inside a function.

Explanation

The const qualifier promises that the program will not modify the object through that identifier; an attempt to assign to it is a constraint violation. Where the object is stored is an implementation detail, and initialisation is normally part of the declaration.

Question 11C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

What does the declaration static int count; at file scope mean?

  1. count has internal linkage and static storage duration. Correct answer.
  2. count can be used only inside the function where it is declared.
  3. count is stored in a register for faster access.
  4. count has external linkage and automatic storage duration.

Explanation

At file scope, static gives the identifier internal linkage so it is visible only within that translation unit, while the object still has static storage duration. It is not automatic and is not limited to a function block.

Question 12C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which of these is a valid octal integer constant in C?

  1. 0x755
  2. 0755 Correct answer.
  3. 755
  4. 0b755

Explanation

An octal constant begins with the digit 0 followed by octal digits, so 0755 is valid. The 0x prefix makes a hexadecimal constant, a leading digit other than 0 makes a decimal constant, and 0b is not an ANSI C prefix.

Question 13C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

In the expression 3.0f, what does the f suffix indicate?

  1. The constant is a hexadecimal value.
  2. The constant is an integer converted to double.
  3. The constant has type long double.
  4. The constant has type float. Correct answer.

Explanation

A floating constant with the f or F suffix has type float; without a suffix it has type double, and with l or L it has type long double. The suffix does not affect the base or the value.

Question 14C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which declaration correctly defines a symbolic constant named LIMIT with value 100 using the preprocessor?

  1. #define LIMIT = 100
  2. const LIMIT = 100;
  3. #define LIMIT 100 Correct answer.
  4. define LIMIT 100

Explanation

The #define directive replaces the identifier LIMIT with the token sequence 100 before compilation, and no equals sign or semicolon is used. A const declaration would also need a type specifier.

Question 15C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which of the following is a valid C token category in ANSI C?

  1. comment
  2. punctuator Correct answer.
  3. bracket
  4. semicolon

Explanation

ANSI C defines keywords, identifiers, constants, string literals, operators and punctuators as token categories. Semicolons and brackets are individual punctuators rather than categories, and comments are removed during translation before tokenisation.

Question 16C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

What is the value of the character constant 'A' when used in an integer context on a system using ASCII?

  1. The letter A itself
  2. 65 Correct answer.
  3. 0
  4. 97

Explanation

A character constant has type int and its value is the numeric code of the character in the execution character set. In ASCII, uppercase A is 65, while 97 is the code for lowercase a.

Question 17C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which statement about the C character set is correct?

  1. The basic source character set includes the 26 uppercase letters, 26 lowercase letters, 10 digits and certain punctuation and control characters. Correct answer.
  2. The basic source character set includes every Unicode character.
  3. The basic source character set excludes the underscore character.
  4. The basic source character set contains only the digits 0 to 9.

Explanation

ANSI C defines a basic source character set made up of the Latin letters in both cases, the ten decimal digits, and a set of punctuation and control characters including the underscore and whitespace. Unicode and other extended characters are outside the basic set.

Question 18C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which declaration creates an integer variable named value with automatic storage duration inside a function?

  1. int value; Correct answer.
  2. extern int value;
  3. register value;
  4. static int value;

Explanation

A plain block-scope declaration such as int value; gives the object automatic storage duration, created on entry and destroyed on exit. The static specifier changes the duration, extern refers to an object defined elsewhere, and register lacks a type specifier.

Question 19C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which of these names is reserved for the implementation and should be avoided by a programmer in ANSI C?

  1. my_value
  2. _value Correct answer.
  3. Value2
  4. value_2

Explanation

Identifiers beginning with an underscore followed by a lowercase letter, and all identifiers beginning with two underscores, are reserved for the implementation at file scope. The other names start with a letter or use underscores internally, which is permitted.

Question 20C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

What is the type of the integer constant 2147483648 on a 32-bit system where int is 32 bits?

  1. long or long long, depending on which can represent it Correct answer.
  2. float
  3. int
  4. unsigned char

Explanation

The type of an unsuffixed decimal constant is the first of int, long int and long long int that can represent the value, so a value too large for 32-bit int moves to a wider signed type. It never becomes unsigned char or a floating type.

Question 21C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which statement about initialisation versus assignment in a C declaration is correct?

  1. int a = 5; is invalid because declarations cannot contain values.
  2. int a = 5; initialises a as part of its definition, whereas a = 5; assigns to an existing object. Correct answer.
  3. int a = 5; assigns to a after a is created uninitialised.
  4. a = 5; can appear at file scope outside any function.

Explanation

In a declaration the equals sign introduces an initialiser that becomes part of the object's definition, while a separate assignment statement stores a value into an object that already exists. Assignment statements cannot appear at file scope outside a function.

Question 22C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which of the following correctly declares an unsigned integer variable named count?

  1. unsigned;
  2. int unsigned;
  3. unsigned int count; Correct answer.
  4. unsigned count int;

Explanation

The type specifiers unsigned and int may appear in either order, but they must both precede the identifier count. Writing the identifier between specifiers, omitting it, or omitting the name produces an invalid declaration.

Question 23C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

What does the declaration extern int total; inside a function tell the compiler?

  1. total is created as a new automatic variable on the stack.
  2. total is a constant whose value cannot change.
  3. total is defined in another translation unit or elsewhere in the program. Correct answer.
  4. total is a register variable for fast access.

Explanation

The extern storage-class specifier declares an identifier without defining a new object, so the definition must exist elsewhere. It does not create automatic storage, make the object constant, or request a register.

Question 24C fundamentals: character set, tokens, identifiers, keywords, data types, constants, variables, declarations

Which of these is a valid way to write a string literal in C?

  1. "Karnataka
  2. 'Karnataka'
  3. "Karnataka" Correct answer.
  4. Karnataka

Explanation

A string literal is a sequence of characters enclosed in double quotes, so "Karnataka" is valid. Single quotes are reserved for character constants, a bare word is an identifier, and an unterminated quote is a syntax error.

Question 25Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

In ANSI C, what is the value of the expression 17 / 5 when both operands are int?

  1. 3.4
  2. 3 Correct answer.
  3. 2
  4. 4

Explanation

When both operands of the division operator are of integer type, C performs integer division: the fractional part is discarded (truncation toward zero), so 17/5 yields 3. To obtain 3.4 you must make at least one operand floating-point, for example 17.0/5.

Question 26Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

What does the expression 13 % 4 evaluate to in ANSI C?

  1. 3
  2. 1 Correct answer.
  3. 3.25
  4. 0

Explanation

The modulus operator % yields the remainder after integer division; 4 goes into 13 three times with remainder 1. The % operator is defined only for integer operands, so a floating-point result is impossible here.

Question 27Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

After the declarations int a = 5; the statement a += 3 * 2; leaves a holding which value?

  1. 11 Correct answer.
  2. 10
  3. 13
  4. 16

Explanation

The compound assignment a += expr is equivalent to a = a + (expr), and the right-hand side 3 * 2 is evaluated first because multiplication has higher precedence than assignment. So a becomes 5 + 6 = 11.

Question 28Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

Which ANSI C operator has the highest precedence among the following?

  1. +
  2. &&
  3. ++ (prefix) Correct answer.
  4. <

Explanation

Prefix increment belongs to the unary operator group, which binds tighter than arithmetic, relational and logical operators. The order from highest to lowest here is ++, then +, then <, then &&.

Question 29Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

What is printed by printf("%d", 7 > 4); in ANSI C?

  1. 7
  2. 0
  3. true
  4. 1 Correct answer.

Explanation

Relational operators such as > yield an int result: 1 when the comparison is true and 0 when it is false. Since 7 > 4 is true, the value passed to printf is 1. C has no built-in boolean type in C89, so true is not printed.

Question 30Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

Given int x = 10; what is the value of x after the statement x = x++ + 1; is executed?

  1. 12 Correct answer.
  2. 13
  3. 11
  4. 10

Explanation

Modifying x and also reading it for another purpose within the same expression without an intervening sequence point gives undefined behaviour in ANSI C. In practice on most compilers the post-increment is applied and then the assignment stores 11 + 1, giving 12, which is the value candidates must recognise as the typical outcome. The safe rewrite is x = x + 1; x = x + 1; or simply x += 2;.

Question 31Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

What is the result of the expression 5 & 3 in ANSI C?

  1. 8
  2. 7
  3. 15
  4. 1 Correct answer.

Explanation

Bitwise AND compares each bit position and yields 1 only where both bits are 1. In binary 5 is 101 and 3 is 011; the AND is 001, which is decimal 1.

Question 32Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

What does 6 | 3 evaluate to in ANSI C?

  1. 7 Correct answer.
  2. 5
  3. 9
  4. 2

Explanation

Bitwise OR sets a bit to 1 whenever either operand has a 1 in that position. Binary 110 OR 011 gives 111, which is decimal 7.

Question 33Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

What is the value of 5 ^ 3 in ANSI C?

  1. 6 Correct answer.
  2. 8
  3. 15
  4. 2

Explanation

Bitwise exclusive-OR yields 1 where the two bits differ and 0 where they match. Binary 101 XOR 011 is 110, which is decimal 6.

Question 34Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

For int a = 1;, what does the expression a << 3 produce?

  1. 4
  2. 9
  3. 3
  4. 8 Correct answer.

Explanation

The left-shift operator moves the bit pattern of the left operand to the left by the number of positions given on the right, filling vacated bits with zeros. Shifting 1 (binary 001) left by 3 gives 1000, which is decimal 8, equivalent to multiplying by 2^3.

Question 35Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

Given int p = 4, q = 9; what is the value of the expression p > 5 && q < 10?

  1. 1
  2. 0 Correct answer.
  3. 4
  4. 9

Explanation

Logical AND yields 1 only when both operands are true. Here p > 5 is false (0), so the whole expression is 0, and because && short-circuits, q < 10 is not even evaluated.

Question 36Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

What is the value of the expression !0 + !5 in ANSI C?

  1. 2
  2. 5
  3. 1 Correct answer.
  4. 0

Explanation

The logical NOT operator returns 1 for a zero operand and 0 for any non-zero operand. Therefore !0 is 1 and !5 is 0, and their sum is 1. The operands are treated as truth values, not negated bit by bit.

Question 37Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

Given int m = 7; what is the value of m after the statement m /= 2; executes?

  1. 3.5
  2. 2
  3. 4
  4. 3 Correct answer.

Explanation

The compound assignment m /= 2 is equivalent to m = m / 2, and since both m and 2 are int, integer division truncates toward zero. 7 / 2 is 3, so m holds 3. The result type of the assignment is int, so no fraction can be stored.

Question 38Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

In the expression 2 + 3 * 4 - 6 / 3, what is the evaluation order and final value?

  1. 9, evaluated strictly left to right
  2. 10, because / is done before *
  3. 12, because + and - are done before * and /
  4. 12, because * and / are done before + and - Correct answer.

Explanation

Multiplication and division share higher precedence than addition and subtraction, so 3 * 4 = 12 and 6 / 3 = 2 are computed first. The expression then reduces to 2 + 12 - 2, which is 12.

Question 39Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

Given int i = 5; what is printed by printf("%d %d", i++, ++i);?

  1. 6 7
  2. 5 7 Correct answer.
  3. 5 6
  4. 6 6

Explanation

Function arguments are evaluated in an unspecified order, and modifying i twice without an intervening sequence point makes this expression undefined in ANSI C. On typical implementations the arguments are evaluated right to left, so ++i makes i 6 and i++ yields 6 then increments to 7, printing 5 7. Candidates should recognise that the code is non-portable and should be rewritten as separate statements.

Question 40Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

What is the value of the expression 10 > 5 > 1 in ANSI C?

  1. 0 Correct answer.
  2. 5
  3. 10
  4. 1

Explanation

Relational operators are left-associative, so the expression groups as (10 > 5) > 1. The first comparison yields 1, and 1 > 1 is false, giving 0. Programmers expecting a mathematical chain comparison are surprised by this result.

Question 41Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

In the declaration float f = 9 / 2; what value is stored in f?

  1. 5.0
  2. 4.0 Correct answer.
  3. 4
  4. 4.5

Explanation

The right-hand side 9 / 2 is evaluated first, and because both operands are int the result is the int 3. That int is then converted to float for storage, giving 3.0. To get 4.5 at least one operand must be floating-point, as in 9.0 / 2.

Question 42Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

What is the value of the expression (int)3.9 + 2 in ANSI C?

  1. 6
  2. 3.9
  3. 5.9
  4. 5 Correct answer.

Explanation

The cast (int)3.9 truncates the fractional part and yields 3, so the expression becomes 3 + 2, which is the int 5. A cast converts the value; it does not round it.

Question 43Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

In the expression 5 + 2.0, what is the type of the result?

  1. char
  2. float
  3. double Correct answer.
  4. int

Explanation

When an int and a double are combined, the usual arithmetic conversions promote the int operand to double, so the result has type double. No explicit cast is needed; the promotion happens automatically.

Question 44Operators and expressions: arithmetic, relational, logical, bitwise, assignment, increment/decrement, precedence, type conversion

Given int a = 6, b = 4; what is the value of a > b ? a - b : b - a?

  1. 6
  2. 4
  3. -2
  4. 2 Correct answer.

Explanation

The conditional operator evaluates the condition a > b first; since 6 > 4 is true, it yields the second operand a - b, which is 2. The third operand is not evaluated at all.

Question 45Control structures: if, if-else, switch, for, while, do-while, break, continue, goto

In ANSI C, which control structure guarantees that its body executes at least once, even if the controlling condition is false on entry?

  1. switch
  2. for
  3. do-while Correct answer.
  4. while

Explanation

A do-while loop tests its condition after executing the body, so the body always runs once before any test. The while and for loops test the condition before the first iteration, and switch is a selection statement, not a loop.

Question 46Control structures: if, if-else, switch, for, while, do-while, break, continue, goto

What does the break statement do when it appears inside a for loop in ANSI C?

  1. It skips the rest of the current iteration and starts the next one
  2. It terminates the loop immediately and control passes to the statement after the loop Correct answer.
  3. It exits only the innermost block but continues looping
  4. It restarts the loop from its initialization expression

Explanation

break transfers control out of the nearest enclosing loop or switch, so the remaining iterations never occur. The statement that skips only the current iteration and proceeds to the next is continue, not break.

Question 47Control structures: if, if-else, switch, for, while, do-while, break, continue, goto

Which statement about the controlling expression of an if statement in ANSI C is correct?

  1. Any scalar value is allowed, and zero means false while nonzero means true Correct answer.
  2. Only values of type int may be used as the condition
  3. The expression must evaluate to exactly 1 for the branch to run
  4. Only relational operators such as < and == may appear

Explanation

In C, if accepts any scalar expression, including integers, characters, and pointers. The test is truth-valued: zero is false and any nonzero value is true, so a bare variable such as if (count) is legal.

Question 48Control structures: if, if-else, switch, for, while, do-while, break, continue, goto

How many times does the body of the loop for (i = 1; i <= 5; i++) execute?

  1. 4
  2. Infinite number of times
  3. 6
  4. 5 Correct answer.

Explanation

The loop begins at i = 1 and runs while i is at most 5, giving the values 1, 2, 3, 4, and 5. That is five iterations, after which i becomes 6 and the condition fails.

Question 49Control structures: if, if-else, switch, for, while, do-while, break, continue, goto

In a switch statement, what happens immediately after a matching case label if no break appears at the end of that case?

  1. Control jumps back to the switch expression for re-evaluation
  2. The program reports a compile-time error for the missing break
  3. The switch terminates automatically at the next case label
  4. Execution falls through and continues into the statements of the following case labels Correct answer.

Explanation

A switch label marks an entry point only; execution continues sequentially until a break, return, or the end of the switch is reached. This fall-through behaviour is why break is usually placed after each case.

Question 50Control structures: if, if-else, switch, for, while, do-while, break, continue, goto

Which of these expressions is valid as the controlling expression of a switch statement in ANSI C?

  1. A string literal such as "yes"
  2. A floating-point expression such as a double variable
  3. A structure variable holding two integers
  4. An integer expression such as a char or int variable Correct answer.

Explanation

The switch expression must have an integer type, which includes char, short, int, and long, possibly after integer promotion. Floating-point values, strings, and structures cannot be compared with case labels in a switch.