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

C Programming - Questions and

The document provides an overview of the C programming language, including its introduction, history, key features, and structure of a C program. It details the compilation process, variable definitions, data types, operators, and conditional statements, along with example programs for basic tasks. The content serves as a comprehensive guide for understanding and using C programming effectively.

Uploaded by

beeldaajebilaal
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)
2 views7 pages

C Programming - Questions and

The document provides an overview of the C programming language, including its introduction, history, key features, and structure of a C program. It details the compilation process, variable definitions, data types, operators, and conditional statements, along with example programs for basic tasks. The content serves as a comprehensive guide for understanding and using C programming effectively.

Uploaded by

beeldaajebilaal
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

C PROGRAMMING – QUESTIONS AND ANSWERS

1. Explain the introduction to the C programming language.

C is a general-purpose programming language developed for


system and application programming. It is fast, efficient, and
allows direct interaction with computer memory and hardware.
Importance:

Very fast execution

Foundation of many languages like C++, Java

Widely used in system programming

Areas of application:

Operating systems

Embedded systems

Compilers

Device drivers

2. Describe the history of the C language.

C was developed in 1972 by Dennis Ritchie at Bell Laboratories. It


evolved from BCPL and B language and was mainly created to
develop the UNIX operating system. Dennis Ritchie made C
portable, efficient, and powerful.

3. Explain the key features of the C language.


Simple and structured

Portable

Fast execution

Rich set of operators

Supports pointers and memory management

C is powerful and flexible because it allows low-level access to


memory and efficient use of hardware.

4. Describe the structure of a C program.

A C program consists of:

1. Header files

2. Main function

3. Declarations

4. Statements

Example:

#include <stdio.h>

int main() {
printf("Hello World");
return 0;
}
---

5. Explain the compilation process in C.

The phases are:

1. Preprocessing

2. Compilation

3. Assembly

4. Linking

5. Execution

---

6. Define variables in C.

A variable is a named memory location used to store data.

Rules for naming identifiers:

Must start with a letter or underscore

Cannot start with a number

No special symbols

Cannot use keywords

Example:

int age;
float salary;
---

7. Discuss different data types in C.

int – stores whole numbers

float – stores decimal numbers

char – stores single characters

Example:

int a = 10;
float b = 2.5;
char c = 'A';

---

8. Explain type conversion in C.

Implicit conversion: automatic

int a = 5;
float b = a;

Explicit conversion: manual

float x = 5.5;
int y = (int)x;

---

9. Describe arithmetic, assignment, and increment operators.

Arithmetic: + - * / %

Assignment: = += -=

Increment: ++ --
Example:

a += 5;
a++;

---

10. Explain bitwise and bit shift operators.

Bitwise operators: & | ^ ~


Shift operators: << >>

Example:

int a = 4 << 1;

---

11. Discuss relational, logical, and conditional operators.

Relational: > < == !=

Logical: && || !

Conditional: ?:

Used in decision-making.

---

12. Explain input and output functions in C.

printf() → output

scanf() → input

int x;
scanf("%d", &x);
printf("%d", x);

---

13. Explain conditional statements in C.

if

if-else

else-if

nested if

---

14. Program to add two numbers

#include <stdio.h>
int main() {
int a, b, sum;
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum = %d", sum);
return 0;
}

---

15. Program to display area of rectangle

#include <stdio.h>
int main() {
int l, w;
scanf("%d %d", &l, &w);
printf("Area = %d", l * w);
return 0;
}
---

16. Program to display your age

#include <stdio.h>
int main() {
int age;
scanf("%d", &age);
printf("Your age is %d", age);
return 0;
}

17. Program to display total and average of four numbers

#include <stdio.h>
int main() {
int a, b, c, d, total;
float avg;
scanf("%d %d %d %d", &a, &b, &c, &d);
total = a + b + c + d;
avg = total / 4.0;
printf("Total = %d\nAverage = %.2f", total, avg);
return 0;
}

You might also like