0% found this document useful (0 votes)
7 views15 pages

Theory PDF

The document provides an overview of the C programming language, including its features, applications, and fundamental concepts such as algorithms, flowcharts, pseudocode, keywords, tokens, identifiers, escape sequences, errors, loops, and functions. It discusses various programming constructs like decision statements, arrays, recursion, and operators, along with their definitions and examples. Additionally, it highlights the importance of structured programming and the foundational role of C in modern programming languages.

Uploaded by

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

Theory PDF

The document provides an overview of the C programming language, including its features, applications, and fundamental concepts such as algorithms, flowcharts, pseudocode, keywords, tokens, identifiers, escape sequences, errors, loops, and functions. It discusses various programming constructs like decision statements, arrays, recursion, and operators, along with their definitions and examples. Additionally, it highlights the importance of structured programming and the foundational role of C in modern programming languages.

Uploaded by

cisop24202
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

THEORY

1. WRITE ABOUT C LANGUAGE.


C is a general-purpose, structured, and procedural programming language developed by Dennis Ritchie in 1972 at Bell
Laboratories. It was mainly developed to create system software and operating systems. The UNIX operating system was
written in C language.

C language is known for its simplicity, efficiency, and powerful features. It provides low-level access to memory using
pointers, which makes it suitable for system programming.

Features of C Language:

1) Structured Programming: Programs are divided into functions.

2) Portable: C programs can run on different machines with little or no modification.

3) Efficient and Fast: C programs execute quickly.

4) Rich Library: It provides many built-in functions.

5) Supports Pointers: Allows direct memory access.

Applications of C: Operating systems , Embedded systems , Compilers , System software , Game development

Thus, C language is considered the foundation of modern programming languages like C++ and Java.

2. WHAT IS ALGORITHM?
An algorithm is a step-by-step procedure or set of instructions designed to solve a specific problem. It describes the logic

of a program in a simple and clear manner before writing the actual code.

An algorithm must have the following characteristics:

1) Input: It should accept zero or more inputs.

2) Output: It should produce at least one output.

3) Definiteness: Each step must be clear and unambiguous.

4) Finiteness: The algorithm must terminate after a finite number of steps.

5) Effectiveness: Each step should be simple and executable.

Example: Algorithm to find sum of two numbers:

Step 1: Start

Step 2: Read two numbers

Step 3: Add the numbers


Step 4: Display the result

Step 5: Stop

Thus, an algorithm is a logical blueprint of a program that helps in planning and solving problems efficiently.

3. WHAT IS FLOWCHART?
A flowchart is a graphical representation of an algorithm or a program. It shows the step-by-step execution of a process
using different symbols and arrows.

A flowchart helps in understanding the logic of a program before writing the actual code. It makes the program easy to
design, analyze, and debug.

Common Symbols Used in Flowchart:

1) Terminal Symbol (Oval): Represents the Start and End of a program.

2) Process Symbol (Rectangle): Represents calculations or instructions.

3) Input/Output Symbol (Parallelogram): Represents input from user or output to screen.

4) Decision Symbol (Diamond): Represents a condition check (Yes/No or True/False).

5) Arrow: Shows the direction of flow of the program.

Advantages of Flowchart:

- Makes logic clear and easy to understand.

- Helps in finding errors.

- Useful for planning before coding.

DISADVANTAGES OF FLOWCHART

1) Time Consuming: Drawing a flowchart takes more time, especially for large programs.

2) Difficult to Modify: If any change is required, the flowchart must be redrawn again.

3) Complex for Large Programs: For big programs, the flowchart becomes very large and difficult to understand.

4) Space Consuming: It requires more space on paper.

5) Not Practical for Detailed Logic: Very detailed program logic makes the flowchart complicated and confusing.

Thus, although flowcharts are useful, they are not always practical for large and complex programs.

4. WHAT IS PSEUDOCODE?
Pseudocode is an informal and simple way of writing the logic of a program using plain English mixed with programming-
like statements. It is written before the actual code.

Pseudocode is not written in any specific programming language, so it does not follow strict syntax rules. It is only used
to understand and explain the logic of a program clearly.
Features of Pseudocode:

- Easy to read and understand.

- Uses simple English statements.

- Does not require proper syntax.

- Helps in converting algorithm into program.

Example: Pseudocode to find sum of two numbers:

START

INPUT A, B

SET SUM = A + B

PRINT SUM

STOP

Advantages: Makes program logic clear , Helps in planning before coding , Easy to modify and debug.

5. WHAT ARE KEYWORDS IN C?


Keywords are reserved words in C programming that have predefined meanings. These words are part of the C language
and cannot be used as variable names, function names, or identifiers.

Each keyword performs a specific function in the program, such as defining data types, control statements, or storage
classes.

Examples of Keywords: int, float, char, if, else, for, while, do, switch, case, break, return, void, etc.

C language has 32 standard keywords.

6. WHAT ARE TOKENS IN C?


Tokens are the smallest individual units of a C program. The compiler breaks a program into tokens while compiling.

In simple words, tokens are the basic building blocks of a C program.

Types of Tokens in C:

1) Keywords 2) Identifiers 3) Constants 4) Strings 5) Operators 6) Special Symbols

Example: int a = 10;

Here: int is keyword , a is identifier , = is operator , 10 is constant , ; is special symbol

7. WHAT IS IDENTIFIER IN C?
An identifier is the name given to variables, functions, arrays, structures, or any other user-defined elements in a C
program.

Identifiers are used to identify these elements uniquely in the program.

Rules for Identifiers:

1) It must start with a letter (A–Z or a–z) or an underscore (_).

2) It cannot start with a number.

3) It cannot contain special characters except underscore.

4) It cannot be a keyword.

5) It is case-sensitive.

Example: int age; , float total_marks;

8. WHAT ARE ESCAPE SEQUENCES IN C?


Escape sequences are special characters used inside strings to perform special functions. They start with a backslash (\).

Common Escape Sequences:

\n → New line

\t → Tab space

\\ → Backslash

\" → Double quote

\b → Backspace

Example:

printf("Hello\nWorld");

9. WHAT IS ERRORS IN C PROGRAMMING


Errors are mistakes in a program that cause the program to produce incorrect results or stop execution.

Types of Errors in C:

1) Syntax Error
These errors occur when the rules of C language are not followed.

Example: Missing semicolon (;) , Wrong spelling of keywords

Syntax errors are detected at compile time.

2) Runtime Error:
These errors occur during the execution of the program.
Example: Division by zero , Accessing invalid memory

Runtime errors are detected while the program is running.

3) Logical Error:
These errors occur when the program runs successfully but produces wrong output.

Example: Using wrong formula , Wrong condition in if statement

Logical errors are difficult to detect because the program does not show any error message.

4) Linker error
These errors occur during the linking stage of program execution. They happen when the linker is unable to find the
definition of a function or variable used in the program.

Example: Calling a function without defining it.

Linker errors are detected after compilation but before execution.

5) Semantic error
These errors occur when the program is syntactically correct but the meaning of the statement is wrong.

Example: Assigning a string value to an integer variable.

Semantic errors are related to incorrect data types or invalid operations.

10. EXPLAIN TOP DOWN APPROACH.


Top Down Approach is a method in which a large problem is divided into smaller and simpler parts step by step.

In this approach, we start from the main problem and then break it into sub-modules. Each module is further divided
until it becomes easy to understand and implement. This is also called stepwise refinement.

Key Points:

1. Starts from main problem.

2. Divides into smaller modules.

3. Easy to manage and understand.

4. Used in structured programming.

Example:

Main Program → Sub Program → Smaller Functions

11. WHAT ARE JUMP STATEMENTS IN C? EXPLAIN.


Jump statements are those statements which transfer the control ofexecution from one part of the program to another
part.

In C language, jump statements are:

1. break

2. continue
3. goto

4. return

These statements are mainly used inside loops, functions, or blocks to change the normal flow of execution.

Example:

break → exits from loop

continue → skips current iteration

return → exits from function

goto → jumps to a labeled statement

12. WHAT IS GOTO STATEMENT IN C?


The goto statement is a jump statement used to transfer control to a labeled statement within the same function.

When the goto statement is executed, control directly moves to the specified label.

Note:

- It is generally not recommended because it makes the program

difficult to read and maintain.

- It should be used only when necessary.

13. WHAT IS RETURN STATEMENT IN C?


The return statement is a jump statement used to terminate a function and send control back to the calling function.

It can return a value (in case of non-void function).

It can also return nothing (in case of void function).

Example: return 0; → returns value , return; → returns nothing

It is mainly used to end a function execution.

14. WHAT IS TYPEDEF IN C? EXPLAIN.


typedef is a keyword in C used to create a new name (alias) for an existing data type.

It helps to simplify complex data type names and improves code readability.

Syntax:

typedef existing_datatype new_name;


Example: typedef int number;

number a = 10;

15. WHAT IS TYPECASTING IN C? EXPLAIN.


Typecasting is the process of converting one data type into another data type.

Types:

1. Implicit Typecasting (Automatic)


2. Explicit Typecasting (Manual)

Syntax: (datatype) variable;

Example: int a = 10;

float b = (float)a;

It is used when we need to change the data type for calculation or compatibility.

16. WHAT IS VARIABLE?


A variable is a named memory location used to store data in a program. The value stored in a variable can change during
program execution.

In C language, every variable must be declared before it is used. While declaring a variable, we must specify its data
type.

Example: int a; , float price; , char grade;

Here, int, float, and char are data types, and a, price, and grade are variable names.

Rules for Naming Variables:

1) Variable name must start with a letter or underscore.

2) It cannot start with a number.

3) No special characters are allowed except underscore.

4) It cannot be a keyword.

Types of Variables in C:
1) Local Variable: Declared inside a function.

2) Global Variable: Declared outside all functions.

Thus, a variable is used to store and manipulate data in a C program.

17. WHAT IS DATA TYPE IN C?


A data type in C defines the type of data that a variable can store. It tells the compiler how much memory to allocate
and what kind of value the variable will hold.

Data types are necessary to store different kinds of data such as numbers, characters, and decimal values.

Types of Data Types in C:

1) Basic (Primary) Data Types:


These are fundamental data types.

- int → used to store integers

- float → used to store decimal numbers

- char → used to store single characters

- double → used to store large decimal numbers

2) Derived Data Types:


These are formed from basic data types.

- array

- pointer

- function

3) User-defined Data Types:


These are created by the programmer.

- struct

- union

- enum

- typedef

Example:

int age = 20;

float price = 10.5;

char grade = 'A';


Thus, a data type specifies the type of value a variable can store and helps in proper memory management in a program.

18. WHAT IS LOOP?


A loop is a control structure in C programming that is used to execute a block of statements repeatedly as long as a given
condition is true. It helps in reducing repetition of code and makes the program more efficient.

Loops are mainly classified into two types based on condition checking:

1) Entry Controlled Loop:


In this type of loop, the condition is checked before the execution of the loop body. If the condition is false, the loop will
not execute even once. Example: for loop and while loop.

2) Exit Controlled Loop:


In this type of loop, the condition is checked after the execution of the loop body. Therefore, the loop body executes at
least one time even if the condition is false. Example: do-while loop.

Thus, loops are very important in programming for performing repetitive tasks like printing numbers, calculating sums,
and processing arrays.

19. What is a Nested Loop?


A nested loop is a loop inside another loop. The inner loop executes completely for every iteration of the outer loop.

Example:

for(i=1; i<=3; i++)

for(j=1; j<=3; j++)

// statements

Nested loops are commonly used for pattern printing and working with 2D arrays.

20. WHAT IS OPERATORS?


Operators in C are special symbols used to perform operations on variables and constants. They are classified into
differenttypes based on the type of operation they perform.
1) Arithmetic Operators:
These operators are used to perform mathematical calculations. They include addition (+), subtraction (-), multiplication
(*), division (/), and modulus (%). They are mainly used in numeric computations.

2) Relational Operators:
These operators are used to compare two values. The result of a relational operation is either true (1) or false (0).

They include ==, !=, >, <, >=, and <=.

3) Logical Operators:
Logical operators are used to combine two or more conditions. They return true or false depending on the logic.

The main logical operators are AND (&&), OR (||), and NOT (!).

4) Assignment Operators:
These operators are used to assign values to variables. The basic assignment operator is (=). There are also shorthand
assignment operators like +=, -=, *=, /=, and %=.

5) Increment and Decrement Operators:


These operators are used to increase or decrease the value of a variable by one. Increment operator (++), Decrement
operator (--).

6) Bitwise Operators:
Bitwise operators work on binary values (bits). They include &, |, ^, ~, <<, and >>. These are mainly used in low-level
programming.

7) Conditional (Ternary) Operator:


The conditional operator (?:) is used to make a decision in a single line statement. It works as: condition ? expression1 :
expression2;

Thus, operators are essential in C programming for performing calculations, comparisons, logical operations, and
controlling program flow.

21. WRITE ALL DECISION STATEMENTS IN C.


Decision statements are used to control the flow of a program based on certain conditions. They help the program to
take decisions and execute different blocks of code according to whether a condition is true or false.

The main decision statements in C are:

1) if Statement:
The if statement is used to execute a block of code only when a given condition is true.

2) if-else Statement:
The if-else statement is used when there are two possible conditions. If the condition is true, the first block executes.

If the condition is false, the else block executes.

3) else-if Ladder:
The else-if ladder is used when multiple conditions need to be checked. The program checks conditions one by one, and
executes the block of the first true condition.
4) Nested if:
When an if statement is placed inside another if statement, it is called nested if. It is used for checking multiple
dependent conditions.

5) switch Statement:
The switch statement is used to select one block of code from multiple options based on the value of a variable.

The break statement is used to stop execution inside switch. The default case executes when no case matches.

Thus, decision statements are essential in C programming to implement logical decision making in a program.

22. WHAT IS AN ARRAY IN C?


An array is a collection of elements of the same data type stored in contiguous (continuous) memory locations.

In an array

- All elements in an array must be of the same data type.

- Each element is accessed using an index number.

- Indexing in C starts from 0.

- Arrays allow storing multiple values under one variable name.

Syntax: datatype array_name[size];

Example: int arr[5] = {10, 20, 30, 40, 50};

Types of Arrays:

1. One-dimensional array
2. Two-dimensional array (Matrix)

23. WHAT IS FUNCTION?


A function is a self-contained block of code that performs a specific task in a program. It is used to divide a large program
into smaller and manageable parts, which improves readability and reusability.

Functions help in avoiding code repetition and make debugging easier. In C programming, there are two main types of
functions:

1) Library Functions:
These are predefined functions provided by C standard library, such as printf(), scanf(), sqrt(), etc.

2) User-defined Functions:
These are functions created by the programmer according to the requirement of the program.
A function generally contains a return type, function name, parameters, and a function body.

24. WHAT IS RECURSION IN C?


Recursion is a process in which a function calls itself.

A recursive function must have:

1. Base condition (to stop recursion)


2. Recursive call (function calling itself)

Example:

int fact(int n)

if(n==1)

return 1;

else

return n * fact(n-1);

Recursion is commonly used for factorial, Fibonacci, etc.

25. WHAT IS RECURSION IN C?


Recursion is a process in which a function calls itself.

A recursive function must have:

1. Base condition (to stop recursion)


2. Recursive call (function calling itself)

Example:

int fact(int n)

if(n==1)

return 1;

else

return n * fact(n-1);

}
Recursion is commonly used for factorial, Fibonacci, etc.

26. WHAT IS A STRING?


A string in C is a collection of characters terminated by a null character '\0'.

In C, strings are stored as character arrays. The null character '\0' marks the end of the string. Without '\0', the string is
not considered complete.

Syntax: char string_name[size];

Example: char name[6] = "Rohit";

Common String Functions (from string.h):

1. strlen() → finds length of string

2. strcpy() → copies one string to another

3. strcat() → concatenates two strings

4. strcmp() → compares two strings

Strings are widely used for handling text data.

27. WHAT IS A POINTER IN C?


A pointer is a variable that stores the memory address of another variable.

Pointers are declared using the '*' symbol.

'&' operator is used to get the address of a variable.

'*' operator is used to access the value stored at that address

Syntax: datatype *pointer_name;

Example: int a = 10;

int *p;

p = &a;
Advantages:

- Used in dynamic memory allocation.

- Efficient for passing arrays to functions.

- Used in structures and linked lists.

Pointers make C a powerful and flexible language.

28. WHAT IS A COMPILER?


A compiler is a software that converts a high-level language program (like C) into machine language (binary code).

It checks the program for errors. If no errors are found, it generates an executable file. Compilation happens before
program execution.

Example: GCC is a commonly used C compiler.

Steps: Source Code → Compiler → Object Code → Executable File

29. WHAT ARE HEADER FILES IN C?


Header files are files that contain declarations of functions, macros, and standard library definitions.

They are included in a program using #include directive. They provide predefined functions.

Syntax: #include <headerfile.h>

Examples:

#include <stdio.h> → for input/output functions

#include <conio.h> → for console functions

#include <math.h> → for mathematical functions

#include <string.h> → for string functions

30. WHAT IS THE RELATION BETWEEN ASCII CODE AND C LANGUAGE?


ASCII (American Standard Code for Information Interchange) is a character encoding system that assigns a numeric

value to characters.

Relation with C:

- In C language, characters are internally stored as ASCII values.

- The 'char' data type stores characters as integers (their ASCII code).

- We can convert character to ASCII and ASCII to character using typecasting.


Example:

'A' → ASCII value 65

'a' → ASCII value 97

'0' → ASCII value 48

Program:

#include <stdio.h>

int main()

char ch;

printf("Enter a character: ");

scanf("%c", &ch);

printf("ASCII value of %c = %d", ch, ch);

return 0;

You might also like