




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A beginner-friendly collection of C programming notes covering basic definitions, concepts, syntax, coding examples, and important programs explained in a simple and easy-to-understand manner for learning and revision.
Typology: Study notes
1 / 135
This page cannot be seen from the preview
Don't miss anything!





























































































I Introduction to C 3- II Variables, Data types, Constants
III Operators and Expressions
IV Input and Output 18- V Control Statements 21- VI Arrays 28- VII Strings 31- VIII Functions 33- IX Pointers 36- X Structures and Unions 39- XI File Handling 40- XII Dyanamic Memory Allocation
CODING BASED
- I Basic Programs 43- UNIT NO. CHAPTER NAME PAGE NO. - II Arrays 57- - III Loops 63- - IV Patterns 72- - V Arrays 80- - VI Strings 89-Introduction to C
1. What is C language? Answer: C is a general-purpose, structured and high-performance programming language developed by Dennis Ritchie at Bell Laboratories in 1972. It is widely used for system programming, operating systems, embedded systems, and application development. C supports low-level memory manipulation along with high-level constructs, which makes it both powerful and flexible. Due to its efficiency, portability, and closer relation to hardware, C has become the foundation for many modern languages such as C++, Java and Python. 2. Why is C called a structured language? Answer: C is called a structured language because it allows a program to be divided into smaller, manageable units called functions. The structured approach improves readability, debugging, modification, and reusability of
programs. Structured programming avoids the use of “goto” and encourages top-down design, where a problem is solved by breaking it into sub-tasks.
3. Why is C called a middle-level language? Answer: C is called a middle-level language because it contains the features of both high-level and low-level languages. As a high-level language , it supports functions, loops, arrays, and readability. As a low-level language , it provides direct memory access using pointers, manipulation of hardware addresses, and efficient machine-level execution. This combination gives C the power of assembly language with the ease of a structured, high-level language. 4. Features of C language. Answer: Important features of C are: 1. Portability: C programs can run on different machines with little or no modification. 2. Efficiency: C produces fast and optimized machine code. 3. Structured Language: Programs are divided into functions for clarity and maintainability. 4. Rich Library: C supports many built-in functions.
code
7. What is source code and object code? Answer: Source Code: The original program written in a high-level language like C. It is saved with a “.c” extension. Object Code: The machine-level output generated by the compiler. It is usually saved with “.obj” or “.o” extension. This code is later linked to form the executable file. 8. What is a token in C? Name the types of tokens. Answer: A token is the smallest individual unit or element of a C program. The C compiler reads and processes the program by breaking it into tokens. The main types of tokens are: 1. Keywords 2. Identifiers 3. Constants 4. Operators 5. Strings
6.Punctuators / Special symbols
Answer: char → 1 byte int → 2 or 4 bytes float → 4 bytes double → 8 bytes long int → 4 or 8 bytes These sizes help the programmer understand how much memory the program will use.
5. What is a constant? Types of constants. Answer: A constant is a fixed value that does not change during program execution. Constants provide reliability and prevent accidental modification of important values. Types of constants include:
1. What is an operator? Give examples. Answer: An operator is a symbol that tells the compiler to perform a specific mathematical or logical operation on data. Examples: +, -, *, /, %, ==, &&, ||. 2. What are operands? Answer: Operands are the data or variables on which operators act. Example: In a + b, a and b are operands and + is the operator. 3. Types of operators in C. Answer: C supports several types of operators: 1. Arithmetic operators → + - * / % 2. Relational operators → < <= > >= == != 3. Logical operators → && ||! 4. Assignment operators → = += -= *= /= %= 5. Increment/decrement operators → ++ --
9. What is the modulus operator? Where is it used? Answer: The modulus operator % gives the remainder after division. Used in: Finding even/odd Extracting digits Working with cycles or periodic patterns 10. What is an expression? Answer: An expression is a combination of variables, constants, and operators that produce a value. Example: x = a + b * 5; 11. What is operator precedence? Answer: Operator precedence determines the order in which operators are evaluated in an expression. Example:
12. What is associativity? Answer: Associativity defines the direction in which an expression is evaluated when two operators have the same precedence. Most operators are left-to-right associative , except unary operators and assignment operators (right-to-left). 13. What is the size of operator (sizeof)? Answer: sizeof is a compile-time operator that returns the amount of memory (in bytes) used by a data type or variable. Example: sizeof(int) returns 2 or 4 bytes. 14. What is the conditional/ternary operator? Answer: The ternary operator ?: is a shorthand for if-else. Syntax: condition? expression1 : expression If condition is true → expression1 executes, else expression2 executes.
Typecasting is used when performing operations between different data types or when precise control over data conversion is required.
18. What is the sizeof operator? Answer: sizeof is a compile-time unary operator used to determine the memory size (in bytes) of a variable or data type. Example: sizeof(int); // typically 4 bytes It helps in memory management and writing portable code across different systems.
1. Purpose of printf() and scanf() printf() printf() is a standard output function in C. It is used to display text, variables, and results on the screen. It uses format specifiers to print different types of data. scanf() scanf() is a standard input function. It is used to take input from the user through the keyboard. It reads values and stores them into variables using address (&). 2. Format specifiers Format specifiers tell printf()/scanf() what type of data to read or print. Specifi er Meaning %d Integer (int) %f Float (for printf), read float in