Posts

Showing posts from February, 2026

Pointers in C Programming for Beginners with Examples

Pointers in C Programming A pointer in C programming is a variable that stores the memory address of another variable. Pointers are powerful features of C that allow direct memory access. Why Use Pointers? Efficient memory management Pass arguments by reference Work with arrays and functions Used in dynamic memory allocation Declaration of a Pointer Syntax: data_type *pointer_name; Example: int *ptr; Address Operator (&) The & operator is used to get the address of a variable. int num = 10; int *ptr = &num; Dereferencing Operator (*) The * operator is used to access the value stored at the address. printf("%d", *ptr); Complete Example #include <stdio.h> int main() { int num = 25; int *ptr = &num; printf("Value of num = %d\n", num); printf("Address of num = %p\n", &num); printf("Value using pointer = %d", *ptr); return ...

Functions in C Programming for Beginners with Examples

Functions in C Programming A function in C programming is a block of code that performs a specific task. Functions help divide a large program into smaller and manageable parts. Why Use Functions? Reduce code repetition Improve readability Make debugging easier Organize large programs Structure of a Function A function in C has three main parts: Function Declaration (Prototype) Function Definition Function Call 1. Function Declaration Syntax: return_type function_name(parameters); Example: int add(int, int); 2. Function Definition int add(int a, int b) { return a + b; } 3. Function Call #include <stdio.h> int add(int, int); int main() { int result = add(5, 3); printf("Sum = %d", result); return 0; } int add(int a, int b) { return a + b; } Types of Functions in C Library Functions (printf(), scanf(), etc.) User-defined Functions Advantages of Functions ...

Strings in C Programming for Beginners with Examples

Strings in C Programming A string in C programming is a collection of characters stored in an array. Strings are used to store text such as names, messages, and sentences. What is a String? In C, a string is an array of characters that ends with a special character called null character (\0) . Declaration of a String Syntax: char string_name[size]; Example: char name[20]; Initialization of a String char name[] = "Anand"; Here, C automatically adds the null character at the end. Printing a String #include <stdio.h> int main() { char name[] = "Programming"; printf("%s", name); return 0; } The %s format specifier is used to print strings. Common String Functions To use string functions, include: #include <string.h> Function Purpose strlen() Find length of string strcpy() Copy one string to another strcat() Concatenate two strings ...

Arrays in C Programming for Beginners with Examples

Arrays in C Programming An array in C programming is used to store multiple values of the same data type in a single variable. Instead of creating many separate variables, arrays help organize data efficiently. What is an Array? An array is a collection of elements stored in continuous memory locations. Each element is accessed using an index number. Index in C starts from 0 . Declaration of an Array Syntax: data_type array_name[size]; Example: int numbers[5]; This declares an integer array that can store 5 values. Initialization of an Array int numbers[5] = {10, 20, 30, 40, 50}; Here: - numbers[0] = 10 - numbers[1] = 20 - numbers[2] = 30 - numbers[3] = 40 - numbers[4] = 50 Accessing Array Elements #include <stdio.h> int main() { int numbers[3] = {5, 10, 15}; printf("%d\n", numbers[0]); printf("%d\n", numbers[1]); printf("%d\n", numbers[2]); return 0; } ...

break and continue Statements in C Programming

break and continue Statements in C Programming In C programming, break and continue are loop control statements. They are used to change the normal flow of loops like for, while, and do-while. 1. break Statement The break statement immediately stops the loop and exits from it. Syntax: break; Example: #include <stdio.h> int main() { int i; for(i = 1; i This program prints 1 and 2, then stops when i becomes 3. 2. continue Statement The continue statement skips the current iteration and moves to the next loop cycle. Syntax: continue; Example: #include <stdio.h> int main() { int i; for(i = 1; i This program prints 1, 2, 4, and 5. It skips printing 3. Difference Between break and continue break continue Stops the loop completely Skips only one iteration Exits the loop Moves to next iteration Conclusion The break and continue statements give better control over loops....

Loops in C Programming for Beginners with Examples

Loops in C Programming Loops in C programming are used to execute a block of code repeatedly until a condition is satisfied. They help reduce code repetition and make programs efficient. Types of Loops in C for loop while loop do-while loop 1. for Loop The for loop is used when the number of iterations is known. Syntax: for(initialization; condition; update) { // code } Example: #include <stdio.h> int main() { int i; for(i = 1; i <= 5; i++) { printf("%d\n", i); } return 0; } This program prints numbers from 1 to 5. 2. while Loop The while loop executes code while the condition is true. Syntax: while(condition) { // code } Example: #include <stdio.h> int main() { int i = 1; while(i <= 5) { printf("%d\n", i); i++; } return 0; } 3. do-while Loop The do-while loop executes the code at least once, even if the condition ...

Decision Making Statements in C Programming

Introduction:- Decision making statements allow a program to take decisions based on conditions.   They help control the flow of execution in a program. ______________________________ *In C programming, decision making is done using: - if statement - if-else statement - else-if ladder - switch statement -------------------------------------------------- 1. if Statement The if statement executes a block of code only when the condition is true. Syntax: if(condition) {     // code to execute } Example: #include <stdio.h> int main() {     int age = 18;   if(age >= 18) {         printf("You can vote");     }    return 0; } -------------------------------------------------- 2. if-else Statement The if-else statement executes one block if condition is true, otherwise another block. Syntax: if(condition) {     // true block } else {     // false block } Example: #include <stdio.h> int m...

Input and Output in C (printf and scanf)

  Introduction:- Input and Output are important concepts in C programming. Input allows the user to enter data, and output displays the result on the screen. ---------------------------------------------------------------------------------- In C, input and output are handled using functions like printf() and scanf(). Output in C – printf() The printf() function is used to display output on the screen. Example: #include <stdio.h> int main() {     printf (" Hello World ");     return 0 ; } ~This program prints “Hello World” on the screen. ---------------------------------------------------------------------------------- Input in C – scanf():- The scanf() function is used to take input from the user. Example: #include <stdio.h> int main() {     int age ;     scanf (" %d ", & age );     printf (" Your age is %d ", age );     return 0 ; } This program: Takes age as input Stores it in a variable Prints it o...

Variables and Constants in C Programming

  INTRODUCTION:- In C programming, variables and constants are used to store data. They are fundamental concepts that every beginner must understand before writing complex programs. What is a Variable? ~A variable is a name given to a memory location used to store data. The value of a variable can change during program execution. Syntax: data_type variable_name; Example: int age = 18; float salary = 25000.5; In this example: age is a variable of type int salary is a variable of type float Rules for Naming Variables:- Must start with a letter or underscore Cannot start with a number Cannot use C keywords Case-sensitive (Age and age are different) What is a Constant? ~A constant is a value that cannot be changed during program execution. Example: const int year = 2025; **Here, the value of year cannot be modified.** Types of Constants in C:- Integer constants (10, 100, -5) Floating constants (3.14, 2.5) Character constants ('A', 'b') String constants ("Hello") D...

Data Types in C (Complete Beginner Guide)

  Introduction:- In C programming, data types define the type of data a variable can store. * Choosing the correct data type is important for writing efficient and error-free programs. What Are Data Types? A data type tells the compiler: What type of value will be stored How much memory should be allocated What operations can be performed Basic Data Types in C 1. int (Integer):- Used to store whole numbers. Example : int age = 20; 2. float:- Used to store decimal numbers. Example: float price = 99.5; 3. Double:- Used to store large decimal numbers with more precision. Example: double pi = 3.141592; 4. Char:- Used to store a single character. Example : char grade = 'A'; Size of Basic Data Types Data Type:Typical Size int:4 bytes float:4 bytes double:8 bytes char:1 byte (Note: Size may vary depending on system.) Why Data Types Are Important Efficient memory usage Prevents errors Improves program performance Conclusion:- Understanding data types is essential before learning varia...

Basic Structure of a C Program

  Introduction C programming is one of the most important languages for beginners. Before writing any program, it is necessary to understand the basic structure of a C program. Basic Structure of a C Program A simple C program has the following parts: Header files Main function Variable declaration Statements Return statement Example of a Simple C Program -------------------------------------------------- #include <stdio.h> int main() {     printf("Hello, World!");     return 0; } -------------------------------------------------- Explanation of Each Part 1. Header File (#include <stdio.h>) ~It tells the compiler to include standard input-output functions like printf(). 2. Main Function (int main()) ~Execution of every C program starts from the main() function. 3. Statements ~These are instructions given to the computer. Example: printf("Hello, World!"); 4. Return Statement (return 0;) ~It ends the program and returns control to the operating sys...

Features of C Language

  Features of C Language Introduction:- C language is one of the most popular programming languages. It is widely used for learning programming and for developing system-level applications. Main Features of C Language 1. Simple and Easy to Learn C language has a simple syntax, which makes it easy for beginners to understand programming concepts. 2. Fast Execution Programs written in C run very fast because C is a compiled language. 3. Structured Language C supports structured programming. This means a program can be divided into functions, which makes code easy to understand and maintain. 4. Portability C programs can be executed on different machines with little or no modification. 5. Rich Library Support C provides many built-in functions through libraries like stdio.h, math.h, and string.h. 6. Low-Level Access C allows direct access to memory using pointers, which is useful for system programming. Conclusion:- Because of its simplicity, speed, and wide usage, C language is still...

What is C programming?

  What is C Programming? C is a general-purpose programming language developed by Dennis Ritchie in 1972. It is widely used for system programming and application development. Why C Programming is used C language is fast and efficient It is easy to learn for beginners It is used to develop operating systems Many other languages are based on C Simple Example of C Program ....[ #include <stdio.h> int main() {     printf("Hello World");     return 0; } ].... Explanation of the Program #include <stdio.h> is used for input and output functions main() is the starting point of the program printf() prints output on the screen return 0; ends the program Conclusion C programming is a powerful and simple language. It is commonly used by students for learning programming fundamentals and for exam preparation.