1. What is C programming? Write any three features of C.
C programming is a high-level, structured programming language developed by Dennis
Ritchie. It is widely used for system programming, application development, and embedded
systems.
Features of C (any three):
1. Structured Language – C allows programs to be divided into functions, making
programs easy to understand and maintain.
2. Portable Language – C programs can be executed on different machines with little or
no modification.
3. Efficient and Fast – C provides low-level memory access, which makes programs faster
and efficient.
2. What is a variable? Explain the rules for naming
variables in C.
A variable is a named memory location used to store data that can change during the execution
of a program.
Rules for naming variables in C:
1. Variable names must begin with a letter or underscore (_).
2. Only letters, digits, and underscores are allowed.
3. Variable names should not be C keywords (like int, float, return).
4. Variable names are case-sensitive (sum and Sum are different).
5. No spaces or special symbols are allowed.
3. Define loop. Write the syntax for for loop.
A loop is a control structure that allows a block of code to be executed repeatedly as long as a
specified condition is true.
Syntax of for loop:
for(initialization; condition; increment/decrement)
{
// statements
}
The for loop is mainly used when the number of iterations is known in advance.
4. What is an array? Give an example of declaration and
initialization.
An array is a collection of elements of the same data type stored in contiguous memory
locations. Each element is accessed using an index.
Example:
int marks[5] = {80, 85, 90, 75, 88};
Here, marks is an integer array of size 5.
5. What is a function? Differentiate between call by value
and call by reference.
A function is a block of code that performs a specific task and can be reused in a program.
Difference between Call by Value and Call by Reference
Call by Value Call by Reference
Copy of variable is passed Address of variable is passed
Changes do not affect original value Changes affect original value
Uses normal variables Uses pointers
1. Explain the structure of a C program with a suitable
example.
A C program consists of several parts arranged in a specific order to perform a task.
Structure of a C Program:
1. Documentation Section – Contains comments describing the program.
2. Link Section – Includes header files using #include.
3. Definition Section – Defines constants using #define.
4. Global Declaration Section – Declares global variables and functions.
5. main() Function – Entry point of the program.
6. User-defined Functions – Functions defined outside main.
Example Program:
#include <stdio.h>
#define PI 3.14
int main()
{
int r = 5;
float area;
area = PI * r * r;
printf("Area = %f", area);
return 0;
}
2. What are Decision-Making Statements in C? Explain if,
if-else, and switch with examples.
Decision-making statements allow the program to choose different paths of execution based
on conditions.
if Statement
Executes a block of code if the condition is true.
if (a > b)
printf("A is greater");
if-else Statement
Executes one block if the condition is true and another if false.
if (a % 2 == 0)
printf("Even number");
else
printf("Odd number");
switch Statement
Used to select one option from multiple choices.
switch(choice)
{
case 1: printf("Addition");
break;
case 2: printf("Subtraction");
break;
default: printf("Invalid choice");
}
3. Explain the concept of pointers. Discuss pointer
declaration, initialization, and pointer arithmetic with
examples.
A pointer is a variable that stores the address of another variable. Pointers help in dynamic
memory allocation and efficient program execution.
Pointer Declaration
int *p;
Pointer Initialization
int x = 10;
p = &x;
Pointer Arithmetic
Pointer arithmetic allows incrementing or decrementing pointers.
p++; // moves to next memory location
Pointer arithmetic is commonly used with arrays.