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.

Basic C Language Concepts C is a powerful and widely-used programming language known for its simplicity and efficiency. Understanding the fundamental concepts of C is essential for any programmer. Here are some of the basic C language concepts taught in universities like Virtual University (VU): 1. Variables and Data Types: C uses variables to store data. Before using a variable, it must be declared with its data type, such as int, float, char, etc. Data types determine the size and type of data a variable can hold. 2. Input and Output: C provides input/output functions like "printf" and "scanf" to display output on the screen and read input from the user, respectively. 3. Arithmetic Operations: C supports standard arithmetic operations like addition, subtraction, multiplication, division, and modulo. Operators such as +, -, *, /, and % are used for these operations. 4. Conditional Statements: Conditional statements, like "if," "else if," and "else," are used to perform different actions based on specified conditions. 5. Loops: C offers several loop constructs, including "for," "while," and "do-while," to execute a block of code repeatedly until a certain condition is met. 6. Functions: Functions in C are blocks of code that perform specific tasks. They promote code reusability and modularity. A function is defined with a return type, name, parameters, and a function body. 7. Arrays: Arrays are collections of elements of the same data type. They provide a way to store multiple values under a single variable name. 8. Pointers: Pointers are variables that store memory addresses. They are used for memory manipulation, dynamic memory allocation, and efficient passing of data between functions. 9. Strings: In C, strings are arrays of characters terminated by a null character '\0'. String handling functions are used to manipulate strings. 10. Structures: Structures allow developers to define a user-defined data type that can hold multiple variables of different data types under one name. 11. File Handling: C supports file handling operations like opening, reading, writing, and closing files using file pointers. 12. Preprocessor Directives: Preprocessor directives start with a "#" symbol and are processed before the compilation. They are used for macro definitions and conditional compilation. Virtual University (VU) provides comprehensive courses on C programming to equip students with a solid foundation in programming. Practical exercises, assignments, and projects help students apply their knowledge and develop problem-solving skills. Learning C forms a strong basis for aspiring programmers and helps them transition to other programming languages with ease. By mastering the basics of C, students gain the confidence to tackle real-world programming challenges and build a successful career in software development.