2 Lecture
CS410
Midterm & Final Term Short Notes
Basic C Language Concepts
Basic C Language Concepts: C is a powerful, procedural programming language. It employs variables, data types, loops, and conditional statements to create efficient and structured code. Functions facilitate code reusability, while pointers allow
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
1. Question: Which keyword is used to define a constant in C?
a) const
b) constant
c) #define
d) final
Solution: a) const
2. Question: What is the correct syntax to declare a variable in C?
a) variableName;
b) int variableName;
c) variableName = value;
d) int variableName = value;
Solution: b) int variableName;
3. Question: What is the purpose of the "printf" function in C?
a) To read user input
b) To display output on the screen
c) To perform mathematical operations
d) To initialize a variable
Solution: b) To display output on the screen
4. Question: What does the "sizeof" operator return in C?
a) The size of a variable in bytes
b) The value of a variable
c) The data type of a variable
d) The address of a variable
Solution: a) The size of a variable in bytes
5. Question: How do you declare a pointer variable in C?
a) pointerType variableName;
b) int* variableName;
c) int variableName*;
d) *int variableName;
Solution: b) int* variableName;
6. Question: What is the purpose of the "scanf" function in C?
a) To display output on the screen
b) To read user input
c) To perform mathematical operations
d) To initialize a variable
Solution: b) To read user input
7. Question: Which loop is used to execute a block of code repeatedly as long as the condition is true?
a) for loop
b) while loop
c) do-while loop
d) switch loop
Solution: b) while loop
8. Question: What is the output of the following code snippet?
a) 15
b) 10
c) 5
d) Error
Solution: a) 15
9. Question: What is the correct syntax for the ternary operator in C?
a) x ? y : z;
b) x : y ? z;
c) x ? y : : z;
d) : x ? y z;
Solution: a) x ? y : z;
10. Question: What does the "return" statement do in a function in C?
a) It declares a variable.
b) It ends the function's execution.
c) It performs a conditional check.
d) It initializes a variable.
Solution: b) It ends the function's execution.
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
1. Question: What are the basic data types in C?
Answer: The basic data types in C are int, char, float, and double.
2. Question: What is the difference between "int" and "float" data types?
Answer: "int" is used for storing whole numbers, while "float" is used for storing numbers with a fractional part.
3. Question: How do you declare a constant in C?
Answer: Constants can be declared using the "const" keyword followed by the data type, such as "const int PI = 3.14;".
4. Question: Explain the purpose of the "if" statement in C.
Answer: The "if" statement is used for conditional execution. It allows a block of code to be executed only if a specified condition is true.
5. Question: What are loops in C, and why are they used?
Answer: Loops in C, like "for," "while," and "do-while," are used to execute a block of code repeatedly until a certain condition is met. They help in automating repetitive tasks.
6. Question: What is the purpose of the "scanf" function in C?
Answer: The "scanf" function is used to read input from the user during program execution.
7. Question: Explain the difference between "++i" and "i++".
Answer: Both "++i" and "i++" increment the value of variable "i" by one. However, "++i" is the pre-increment operator, while "i++" is the post-increment operator. The main difference lies in when the increment takes place relative to the expression evaluation.
8. Question: How do you use the "switch" statement in C?
Answer: The "switch" statement is used to perform multiple conditional checks based on the value of a variable or expression.
9. Question: What is the purpose of the "sizeof" operator in C?
Answer: The "sizeof" operator returns the size (in bytes) of a variable or data type, helping in memory allocation and manipulation.
10. Question: Explain the concept of arrays in C and how they are declared.
Answer: Arrays are collections of elements of the same data type. They are declared using the syntax: "data_type array_name[size];". Elements in an array can be accessed using their index starting from 0.