0% found this document useful (0 votes)
14 views4 pages

C Programming Basics for Students

The document is a basic C language course designed for students, covering key concepts such as data types, variables, operators, conditional statements, loops, functions, arrays, pointers, structures, unions, and file handling. Each chapter includes examples and exercises to reinforce learning. An answer key is provided for the exercises to assist with understanding.
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)
14 views4 pages

C Programming Basics for Students

The document is a basic C language course designed for students, covering key concepts such as data types, variables, operators, conditional statements, loops, functions, arrays, pointers, structures, unions, and file handling. Each chapter includes examples and exercises to reinforce learning. An answer key is provided for the exercises to assist with understanding.
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

Basic C Language Course – Student Edition (English)

Chapter 1: Introduction to C - C is a high-level programming language developed by Dennis Ritchie in


1972. - Used for system programming, developing OS, and applications.

Topics: 1. History of C 2. Features of C 3. Structure of a C Program

Example Program:

#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}

Exercise: 1. Write a C program to display your name.

Chapter 2: Data Types & Variables - Data Types: int, float, char, double - Variables: Storage for data

Example:

int age = 16;


float price = 99.5;
char grade = 'A';

Exercise: 1. Declare variables for name, age, and marks.

Chapter 3: Operators & Expressions - Arithmetic: +, -, *, /, % - Relational: ==, !=, >, <, >=, <= - Logical: &&,
||, !

Example:

int a = 5, b = 10;
printf("Sum = %d", a + b);

Exercise: 1. Write a program to calculate area of a rectangle.

1
Chapter 4: Conditional Statements - if, if-else, nested if, switch-case

Example:

int marks = 85;


if(marks >= 50)
printf("Pass\n");
else
printf("Fail\n");

Exercise: 1. Write a program to check even or odd number.

Chapter 5: Loops - for, while, do-while

Example:

for(int i=1; i<=5; i++)


printf("%d\n", i);

Exercise: 1. Print first 10 natural numbers using while loop.

Chapter 6: Functions - Functions help to divide programs into modules

Example:

int add(int a, int b) {


return a + b;
}

Exercise: 1. Write a function to calculate factorial of a number.

Chapter 7: Arrays - Arrays store multiple values of same type

Example:

int arr[5] = {1,2,3,4,5};

2
Exercise: 1. Find the sum of all elements in an array.

Chapter 8: Pointers - Pointer stores address of a variable

Example:

int x = 10;
int *p = &x;
printf("%d", *p);

Exercise: 1. Write a program to swap two numbers using pointers.

Chapter 9: Structures & Unions - Structures: store different data types together - Unions: store different
data types in same memory location

Example:

struct Student {
char name[20];
int age;
};

Exercise: 1. Create a structure for Book with title, author, price.

Chapter 10: File Handling (Basics) - fopen(), fclose(), fprintf(), fscanf()

Example:

FILE *fp;
fp = fopen("[Link]", "w");
fprintf(fp, "Hello");
fclose(fp);

Exercise: 1. Write a program to read and write data to a file.

Answer Key (Basic) 1. Hello, World! program prints Hello, World! 2. Variable declaration examples: int age;
float price; char grade; 3. Area of rectangle: area = length * breadth 4. Even/Odd: if(n%2==0) even else odd

3
5. Loops: for/while printing numbers 6. Functions: add, factorial function 7. Arrays: sum using for loop 8.
Pointers: swap using temp or direct pointer arithmetic 9. Structures: struct Book {char title[20]; char
author[20]; float price;}; 10. File: fopen(), fprintf(), fclose() usage

You might also like