Back to Practice C Programming

C Basics - Practice MCQs for CCAT

50 Questions Section B: Programming C Programming

C Basics Question Bank for C-CAT

Topic-wise C Basics MCQs for CDAC C-CAT preparation with answers and explanations.

Q1.
Who is the creator of C programming language?
AJames Gosling
BBjarne Stroustrup
CDennis Ritchie
DKen Thompson
Show Answer & Explanation

Correct Answer: C - Dennis Ritchie

C was developed by Dennis Ritchie at Bell Labs in the early 1970s.

Q2.
C language was originally developed for which operating system?
ADOS
BWindows
CLinux
DUNIX
Show Answer & Explanation

Correct Answer: D - UNIX

C was developed to write the UNIX operating system.

Q3.
Which of the following is a valid C standard?
APython 3
BC++11
CJava 8
DC89
Show Answer & Explanation

Correct Answer: D - C89

C89 (ANSI C) is one of the official C language standards.

Q4.
Which of the following is NOT a keyword in C?
Aauto
Bregister
Cvolatile
Dboolean
Show Answer & Explanation

Correct Answer: D - boolean

C does not have a built-in boolean keyword.

Q5.
Which data type is used to store a single character?
Aint
Bchar
Cfloat
Ddouble
Show Answer & Explanation

Correct Answer: B - char

char data type is used to store a single character.

Q6.
What is the size of int data type in most 64-bit systems?
A2 bytes
B4 bytes
C8 bytes
DDepends on compiler
Show Answer & Explanation

Correct Answer: B - 4 bytes

On most modern systems, int occupies 4 bytes.

Q7.
Which modifier is used to increase the range of an integer?
Ashort
Bsigned
Clong
Dconst
Show Answer & Explanation

Correct Answer: C - long

The long modifier increases the size/range of integer.

Q8.
Which qualifier makes a variable read-only?
Avolatile
Bconst
Cregister
Dstatic
Show Answer & Explanation

Correct Answer: B - const

const prevents modification of a variable.

Q9.
What is the default return type of main() in C?
Avoid
Bchar
Cfloat
Dint
Show Answer & Explanation

Correct Answer: D - int

By default, main() returns an integer value.

Q10.
Which header file is required for printf()?
Astdlib.h
Bconio.h
Cmath.h
Dstdio.h
Show Answer & Explanation

Correct Answer: D - stdio.h

printf() is declared in stdio.h.

Q11.
Which symbol is used to terminate a statement in C?
A;
B:
C.
D,
Show Answer & Explanation

Correct Answer: A - ;

Every C statement ends with a semicolon.

Q12.
Which of the following is a valid variable name?
A2num
B_num
Cfloat
Dnum-1
Show Answer & Explanation

Correct Answer: B - _num

Variable names can start with underscore.

Q13.
Which keyword is used to declare a constant?
Adefine
Bconst
Cstatic
Dvolatile
Show Answer & Explanation

Correct Answer: B - const

const keyword declares read-only variables.

Q14.
Which function is used to read formatted input?
Ascanf()
Bprintf()
Cgets()
Dputs()
Show Answer & Explanation

Correct Answer: A - scanf()

scanf() is used for formatted input.

Q15.
Which data type has the highest precision?
Afloat
Bdouble
Clong double
Dint
Show Answer & Explanation

Correct Answer: C - long double

long double provides highest floating-point precision.

Q16.

What is the output of the following code?

int x = 5;
printf("%d", x);
A0
B5
CGarbage
DError
Show Answer & Explanation

Correct Answer: B - 5

x is initialized to 5 and printed.

Q17.
Which of the following is NOT a basic data type?
Aint
Bfloat
Carray
Dchar
Show Answer & Explanation

Correct Answer: C - array

Array is a derived data type.

Q18.
Which keyword tells compiler not to optimize a variable?
Aconst
Bstatic
Cvolatile
Dextern
Show Answer & Explanation

Correct Answer: C - volatile

volatile prevents compiler optimizations.

Q19.
Which operator is used to get address of a variable?
A&
B*
C%
D#
Show Answer & Explanation

Correct Answer: A - &

& operator returns the address of a variable.

Q20.
Which of the following is true about C language?
AObject oriented
BPlatform independent
CPlatform dependent
DMarkup language
Show Answer & Explanation

Correct Answer: C - Platform dependent

C programs depend on underlying hardware and OS.

Q21.
Which of the following correctly prints an integer variable x?
Aprintf(%d, x);
Bprint(x);
Cprintf("%d", x);
Dscanf("%d", x);
Show Answer & Explanation

Correct Answer: C - printf("%d", x);

printf with %d format specifier is used to print integers.

Q22.
What is the size of char data type in C?
ADepends on compiler
B2 bytes
C4 bytes
D1 byte
Show Answer & Explanation

Correct Answer: D - 1 byte

char always occupies 1 byte in C.

Q23.
Which of the following is a correct declaration?
Aunsigned int x;
Bunsigned x int;
Cint unsigned x;
Dsigned float x;
Show Answer & Explanation

Correct Answer: A - unsigned int x;

Correct syntax is modifier followed by data type.

Q24.
Which keyword is used to store a variable in CPU register?
Aauto
Bregister
Cstatic
Dvolatile
Show Answer & Explanation

Correct Answer: B - register

register suggests the compiler to store variable in CPU register.

Q25.

What will be the output?

int a = 10;
printf("%d", sizeof(a));
A2
BDepends on system
C8
D4
Show Answer & Explanation

Correct Answer: D - 4

sizeof(int) is typically 4 bytes on modern systems.

Q26.
Which of the following is a valid constant?
A10
B10.5
C'A'
DAll of the above
Show Answer & Explanation

Correct Answer: D - All of the above

Integer, floating, and character constants are valid.

Q27.
Which escape sequence is used for new line?
A\t
B\n
C\r
D\b
Show Answer & Explanation

Correct Answer: B - \n

\n moves the cursor to next line.

Q28.

What is the output?

printf("Hello
World");
AHello then World in next line
BHelloWorld
CHello\nWorld
DHello World
Show Answer & Explanation

Correct Answer: A - Hello then World in next line

\n causes a line break.

Q29.
Which header file is needed for sizeof operator?
Astdio.h
BNo header required
Cstdlib.h
Dmath.h
Show Answer & Explanation

Correct Answer: B - No header required

sizeof is a compile-time operator.

Q30.
Which of the following is NOT allowed in variable names?
AAlphabets
BDigits
CSpecial symbols
DUnderscore
Show Answer & Explanation

Correct Answer: C - Special symbols

Special symbols like @, # are not allowed.

Q31.
Which keyword is used to declare global variables?
Aextern
Bstatic
Cauto
Dregister
Show Answer & Explanation

Correct Answer: A - extern

extern is used to declare global variables across files.

Q32.

What will be the output?

int x;
printf("%d", x);
A0
BRuntime error
CCompilation error
DGarbage value
Show Answer & Explanation

Correct Answer: D - Garbage value

Uninitialized local variables contain garbage values.

Q33.
Which data type is used to store decimal values?
Aint
Bfloat
Cchar
Dvoid
Show Answer & Explanation

Correct Answer: B - float

float stores decimal (fractional) values.

Q34.
Which of the following is true about volatile keyword?
APrevents optimization
BPrevents modification
CMakes variable global
DStores in register
Show Answer & Explanation

Correct Answer: A - Prevents optimization

volatile tells compiler value may change unexpectedly.

Q35.
Which operator is used to determine size of data type?
Asize
Blengthof
Csizeof
Dtype
Show Answer & Explanation

Correct Answer: C - sizeof

sizeof operator returns memory size in bytes.

Q36.
What is the correct format specifier for double?
A%lf
B%f
C%d
D%c
Show Answer & Explanation

Correct Answer: A - %lf

double uses %lf in scanf and printf.

Q37.
Which of the following is a correct comment in C?
A// comment
BBoth A and B
C# comment
D/* comment */
Show Answer & Explanation

Correct Answer: B - Both A and B

C supports both single-line and multi-line comments.

Q38.

What is the output?

printf("%c", 65);
A65
BGarbage
CError
DA
Show Answer & Explanation

Correct Answer: D - A

ASCII value 65 represents character 'A'.

Q39.
Which data type is used when function returns nothing?
Avoid
Bnull
Cint
Dchar
Show Answer & Explanation

Correct Answer: A - void

void indicates no return value.

Q40.
Which of the following correctly ends the main function?
Astop;
Breturn 0;
Cexit;
Dbreak;
Show Answer & Explanation

Correct Answer: B - return 0;

return 0 indicates successful execution.

Q41.
Which of the following is NOT a valid C data type?
Afloat
Bdouble
Cstring
Dchar
Show Answer & Explanation

Correct Answer: C - string

'string' is not a built-in data type in C. Strings are represented as arrays of characters (char[]). The valid primitive data types include int, float, double, char, and void.

Q42.

What will be the output of the following code?

int x = 5;
printf("%d", sizeof(x++));
printf("%d", x);
A45
B46
C55
DCompilation error
Show Answer & Explanation

Correct Answer: A - 45

The sizeof operator is evaluated at compile time, so the expression x++ inside sizeof is never executed at runtime. Therefore x remains 5. sizeof(int) is typically 4 bytes on most systems. The first printf prints 4, the second prints 5 (since x was never incremented). Output: 45.

Q43.
Which keyword is used to prevent modification of a variable's value in C?
Astatic
Bregister
Cvolatile
Dconst
Show Answer & Explanation

Correct Answer: D - const

The 'const' keyword makes a variable read-only after initialization, preventing any modification to its value. 'static' controls storage duration, 'volatile' prevents compiler optimization, and 'register' suggests storing in a CPU register.

Q44.
What is the range of values for an unsigned char in C (assuming 8-bit byte)?
A0 to 255
B0 to 127
C-128 to 127
D-255 to 255
Show Answer & Explanation

Correct Answer: A - 0 to 255

An unsigned char uses all 8 bits for magnitude (no sign bit), giving a range of 0 to 28 - 1 = 255. A signed char uses one bit for sign, giving -128 to 127.

Q45.

What will be the output?

int a = 10, b = 20;
printf("%d", a, b);
A10 20
B10
C20
DCompilation error
Show Answer & Explanation

Correct Answer: B - 10

There is only one %d format specifier but two arguments are passed. The printf function will print the first matching argument (10) and ignore the extra argument b. This is valid C and does not cause a compilation error, though it may generate a warning.

Q46.
Which of the following variable declarations is invalid in C?
Aint _count = 5;
Bchar letter = 'A';
Cfloat 2ndValue = 3.14;
Ddouble _rate_1 = 9.8;
Show Answer & Explanation

Correct Answer: C - float 2ndValue = 3.14;

Variable names in C cannot begin with a digit. '2ndValue' starts with the digit 2, making it an invalid identifier. Valid identifiers must start with a letter (a-z, A-Z) or underscore (_), followed by letters, digits, or underscores.

Q47.
What does the 'volatile' keyword indicate to the compiler?
AThe variable should be stored in a register
BThe variable cannot be modified after initialization
CThe variable's value may change unexpectedly outside the program's control
DThe variable is visible only within the current file
Show Answer & Explanation

Correct Answer: C - The variable's value may change unexpectedly outside the program's control

'volatile' tells the compiler that a variable's value can be changed by external factors (hardware registers, interrupt service routines, other threads), so the compiler should not optimize reads/writes to that variable and must always fetch it from memory.

Q48.

What is the output of the following code?

printf("%d", (int)3.9 + (int)3.1);
A6
B7
C7.0
D6.0
Show Answer & Explanation

Correct Answer: A - 6

When a float/double is cast to int in C, the fractional part is truncated (not rounded). So (int)3.9 = 3 and (int)3.1 = 3. Therefore 3 + 3 = 6. The %d format prints it as integer 6.

Q49.
Which storage class gives a local variable a lifetime equal to the entire program execution?
Aauto
Bregister
Cextern
Dstatic
Show Answer & Explanation

Correct Answer: D - static

A 'static' local variable is initialized only once and retains its value between function calls throughout the program's lifetime. 'auto' and 'register' variables are destroyed when the function returns. 'extern' is used to declare variables defined in other files.

Q50.

What will the following code print?

char str[] = "CDAC";
printf("%lu", sizeof(str));
A5
B4
C8
DCompilation error
Show Answer & Explanation

Correct Answer: A - 5

The string "CDAC" has 4 visible characters, but C automatically appends a null terminator '\0' at the end. So the character array str contains {'C','D','A','C','\0'}, which is 5 bytes. sizeof(str) returns 5.

Showing 1-10 of 50 questions