0% found this document useful (0 votes)
8 views7 pages

Unit 1-Introduction to C Programming

The document is a question bank for a C programming course, covering multiple-choice questions (MCQs) and descriptive questions related to the fundamentals of C programming. It includes topics such as variable names, data types, compiler design, preprocessor directives, and input/output functions. Additionally, it contains programming tasks that require writing C code to demonstrate various concepts.

Uploaded by

rengokuakazaabcd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Unit 1-Introduction to C Programming

The document is a question bank for a C programming course, covering multiple-choice questions (MCQs) and descriptive questions related to the fundamentals of C programming. It includes topics such as variable names, data types, compiler design, preprocessor directives, and input/output functions. Additionally, it contains programming tasks that require writing C code to demonstrate various concepts.

Uploaded by

rengokuakazaabcd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Veltech Multitech Dr.Rangarajan Dr.

sakunthala Engineering College

Department:Computer Science and Engineering/Cyber Security

231CS111-Programming in C

Year /Sem: I /I Question Bank-Unit I

Introduction To C Programming

S.NO MCQ ANS CHAPTER


1 Which of the following is not a valid C variable name? D 1
a) int number;
b) float rate;
c) int variable_count;
d) int $main;
2 Which of the following is true for variable names in C? C 1
a) They can contain alphanumeric characters as well as
special characters
b) It is not an error to declare a variable to be one of the
keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length
3 Which is valid C expression? B 2
a) int my_num = 100,000;
b) int my_num = 100000;
c) int my num = 1000;
d) int $my_num = 10000;
4 All keywords in C are in ____________ A 2
a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None of the mentioned
5 Which of the following is a stage of compiler design? D 3
a) Semantic analysis
b) Intermediate code generator
c) Code generator
d) All of the mentioned
6 A programmer, writes a program to multiply two numbers D 3
instead of dividing them by mistake, how can this error be
detected?
a) Compiler or interpreter
b) Compiler only
c) Interpreter only
d) None of the mentioned
7 Which of the following is a system program that integrates D 4
a program’s individually compiled modules into a form
that can be executed?
a) Interpreter
b) Assembler
c) Compiler
d) Linking Loader
8 What is the purpose of the #define directive in C/C++? B 5
A)To include header files
B) To define constants or macros
C) To start a conditional compilation block
D) To end a comment block
9 Which of the following preprocessor directives is used to B 5
include a standard library in a C/C++ program?
A) #define
B) #include
C) #ifdef
D) #pragma
10 What is the expected output when a C program containing C 6
the main function with return 0; is executed?
A) The program will terminate with an error.
B) The program will not return any value.
C) The program will execute successfully and return
control to the operating system.
D) The program will enter an infinite loop.
11 Which command is typically used to compile a C program A 6
using the GCC compiler?
A) gcc program.c
B) compile program.c
C) run program.c
D) build program.c
12 Which of the following is a valid way to define a constant A 7
in C?
A) const int x = 10;
B) define x = 10;
C) constant int x = 10;
D) let x = 10;
13 What type of constant is defined using the C 7
#definepreprocessor directive?
A) Literal constant
B) String constant
C) Macro constant
D) Enumerated constant
14 Which of the following is a valid declaration of an integer B 8
variable in C?
A) int 1number;
B) int number;
C) integer number;
D) int number; float number2;
15 What is the size of the char data type in C on most A 8
platforms?
A) 1 byte
B) 2 bytes
C) 4 bytes
D) 8 bytes
16 Which of the following data types can store a decimal C 8
value in C?
A) int
B) char
C) float
D) bool
17 What is the ASCII value of the character 'A' in C? A 9
A) 65
B) 97
C) 32
D) 90
18 What type of token is the following: sum in the expression B 10
int sum = a + b;?
A) Keyword
B) Identifier
C) Operator
D) Constant
19 Which of the following is a valid identifier in C? C 11
A) 1stNumber
B) total#Amount
C) total_amount
D) float
20 Which of the following is a reserved keyword in C? B 11
A) function
B) int
C) variable
D) data
21 What is the correct syntax to declare a variable named age A 12
of type int in C?
A) int age;
B) declare int age;
C) int: age;
D) age int;
22 What is the correct way to assign the value 25 to an integer B 13
variable named num?
A) num := 25;
B) num = 25;
C) num < 25;
D) 25 -> num;
23 What will be the output of the following code? C 13
int num;
num = 10;
num = num + 5;
printf("%d", num);
A) 5
B) 10
C) 15
D) 0
24 Which of the following storage classes in C has the scope C 14
limited to the block in which it is declared?
A) extern
B) static
C) auto
D) register
25 What is the default storage class of a variable declared D 14
inside a function without an explicit storage class specifier
in C?
A) static
B) extern
C)register
D) auto
26 Which of the following functions is used to read a string D 15
from the standard input in C?
A) scanf()
B) getchar()
C) gets()
D) fgets()
27 What does the printf() function return in C? A 16
A) The number of characters printed
B) A boolean value
C) The address of the first character
D) An integer indicating success or failure
28 Which function is commonly used to read a single B 17
character from standard input in C?
A) scanf()
B) getchar()
C) fgets()
D) putchar()
29 What will be the output of the following code if the user B 17
inputs the character 'A'?
char ch;
ch = getchar();
printf("%c", ch);
A) A newline character
B) A
C) 65
D) Nothing
30 What will be the output of the following code? A 18
putchar('B');
putchar('\n');
A) B
B) B\n
C) B (on the same line)
D) B (on a new line)
31 Which of the following functions is used for formatted B 18
output in C?
A) getchar()
B) printf()
C) putchar()
D) fgets()
32 Which of the following functions is used for unformatted D 18
input in C?
A) scanf()
B) printf()
C) fgets()
D) getc()
33 What will be the output of the following C program? D 19
#include <stdio.h>
int main()
{
printf("Hello, World!");
return 0;
}
A) Hello, World!
B) Hello World
C) Compilation error
D) Hello, World!
34 In the following C code snippet, what is the return type of B 19
the main function?
#include <stdio.h>
int main() {
return 0;
}
A) void
B) int
C) float
D) char
35 What will the following code output if the variable x is B 19
initialized to 5?
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x * 2);
return 0;
}
A) 5
B) 10
C) 25
D) 15
PART –B
1 Describe the basic structure of a C program. Include 1
components such as preprocessor directives, the main
function, and the return statement.
2 Explain the difference between a compiler and an 2
interpreter. How do they affect the execution of a C
program?
3 What are preprocessor directives in C? Explain the purpose 3
of #include and #define with examples.
4 Explain the steps involved in executing a C program from 4
writing the code to obtaining the output. Include
compilation and linking stages.
5 Explain the various data types in C (e.g., int, float, char) 5
and their typical sizes. How does the choice of data type
affect memory usage?
6 Define tokens in C programming. What are the different 6
types of tokens? Provide examples of keywords and
identifiers.
7 Explain the concept of variable initialization in C. How 9
does it differ from declaration? Provide an example.
8 Explain the role of operators in value assignment. Provide 12
examples of arithmetic operators and how they can be used
to assign values.
9 Describe the different storage classes in C (auto, register, 13
static, extern). Explain their scope, lifetime, and use cases.
10 Explain the difference between formatted and unformatted 14
input/output in C. Provide examples of functions used for
each.

11 How do you read a character and write a character in C? 14


Discuss the functions involved and their usage with
examples.
12 Write a simple C program to swap two numbers using a 16
temporary variable. Explain each part of the code.
13 Create a C program that calculates the factorial of a 17
number using recursion. Explain how recursion works in
your code.
14 C program that demonstrates assigning values to variables. 18
The program prompts the user to enter two numbers,
assigns them to variables, and then calculates and displays
their sum.
#include <stdio.h>
int main() {
int num1, num2, sum;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
printf("The sum of %d and %d is %d\n", num1, num2,
sum);
return 0;
}
Rectify the error and Explain it with step by step and write
output.
15 Write a C program that demonstrates both formatted and 19
unformatted input and output. The program allows the user
to enter several numbers, then prints them using formatted
and unformatted output.
PART – C
1 Explain the roles of a compiler and an interpreter in the 2
context of C programming. Compare and contrast their
functionalities, advantages, and disadvantages. Include
examples of situations where one might be preferred over
the other.
2 Discuss the basic structure of a C program, detailing its 3
components such as preprocessor directives, the main
function, and return statements. Explain how each
component contributes to the overall functionality of a C
program, and provide a simple example.
3 Define constants and variables in C. Discuss the different 4
data types available in C, including their ranges and
memory requirements. Provide examples of how to declare
and initialize variables of different types.
4 Explain the concepts of character set, C tokens, keywords, 5
and identifiers. Discuss the rules for naming identifiers in
C. How do these elements contribute to the structure and
readability of C programs?
5 Explain how to assign values to variables in C. Discuss the 7
differences between direct assignment and initialization.
Provide examples and explain the impact of variable scope
and storage class on assignment.
6 Explain the syntax and rules for declaring variables. 8
Include examples of both valid and invalid declarations.
7 Describe how to effectively manage input and output 13
operations in C, focusing on both formatted and
unformatted methods and write example program.
8 Provide a detailed example problem that requires the use 16
of variables, constants, and basic arithmetic operations.
Include a clear problem statement, the necessary steps to
solve it, and the final implementation in C. Discuss
potential pitfalls and how to avoid them in your solution.
9 Create a C program that implements a simple calculator 19
capable of performing addition, subtraction, multiplication,
and division. Include error handling for division by zero
and invalid operator inputs. Explain the key components of
the program.

You might also like