0% found this document useful (0 votes)
5 views6 pages

C Programming Notes With Examples

This document provides quick exam notes for C programming, covering essential topics such as the basic structure of a C program, data types, input/output functions, operators, control statements, loops, arrays, strings, functions, recursion, pointers, structures, and file handling. Each section includes example codes to illustrate the concepts. Additionally, it offers an exam writing tip for structuring answers.

Uploaded by

Abdul rahoof
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)
5 views6 pages

C Programming Notes With Examples

This document provides quick exam notes for C programming, covering essential topics such as the basic structure of a C program, data types, input/output functions, operators, control statements, loops, arrays, strings, functions, recursion, pointers, structures, and file handling. Each section includes example codes to illustrate the concepts. Additionally, it offers an exam writing tip for structuring answers.

Uploaded by

Abdul rahoof
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

C Programming Quick Exam Notes With

Example Codes
Simple English + Point Wise Notes + Important Example Programs

1. Basic Structure of C Program


• Every C program starts from main() function.
• Header files are included using #include.
• Statements end with semicolon (;).

#include<stdio.h>

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

2. Data Types and Variables


• int stores integers.
• float stores decimal numbers.
• char stores characters.

#include<stdio.h>

int main()
{
int age = 18;
float mark = 95.5;
char grade = 'A';

printf("%d\n", age);
printf("%f\n", mark);
printf("%c", grade);

return 0;
}

3. Input and Output


• printf() displays output.
• scanf() takes input from user.

#include<stdio.h>

int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);

printf("You entered %d", num);

return 0;
}

4. Operators
• Arithmetic operators: +, -, *, /, %.
• Relational operators compare values.
• Logical operators combine conditions.

#include<stdio.h>

int main()
{
int a = 10, b = 5;

printf("%d\n", a+b);
printf("%d\n", a-b);
printf("%d\n", a*b);

return 0;
}

5. If Else Statement
• Used for decision making.
• Condition true → if block executes.
• Condition false → else block executes.

#include<stdio.h>

int main()
{
int age = 20;

if(age >= 18)


{
printf("Eligible");
}
else
{
printf("Not Eligible");
}

return 0;
}

6. Switch Statement
• Used for multiple choices.
• break stops execution.

#include<stdio.h>

int main()
{
int day = 2;

switch(day)
{
case 1:
printf("Monday");
break;

case 2:
printf("Tuesday");
break;

default:
printf("Invalid");
}

return 0;
}

7. Loops
• for loop repeats fixed times.
• while loop checks condition first.
• do while executes at least once.

#include<stdio.h>

int main()
{
int i;

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


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

return 0;
}

8. Arrays
• Array stores multiple values.
• Index starts from 0.

#include<stdio.h>

int main()
{
int a[3] = {10,20,30};
printf("%d", a[1]);

return 0;
}

9. Strings
• String is collection of characters.
• Stored in char array.

#include<stdio.h>

int main()
{
char name[] = "Abdul";

printf("%s", name);

return 0;
}

10. Functions
• Function is reusable block of code.
• Improves modularity.

#include<stdio.h>

void greet()
{
printf("Welcome");
}

int main()
{
greet();

return 0;
}

11. Recursion
• Function calls itself.
• Must contain stopping condition.

#include<stdio.h>

int fact(int n)
{
if(n==1)
return 1;

return n * fact(n-1);
}

int main()
{
printf("%d", fact(5));

return 0;
}

12. Pointers
• Pointer stores address of variable.
• & gives address.
• * accesses value.

#include<stdio.h>

int main()
{
int a = 10;
int *p;

p = &a;

printf("%d", *p);

return 0;
}

13. Structure
• Structure stores different data types together.

#include<stdio.h>

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

int main()
{
struct Student s1 = {1, "Abdul"};

printf("%d", [Link]);

return 0;
}

14. File Handling


• Files are used for permanent storage.
• fopen() opens file.
• fclose() closes file.

#include<stdio.h>
int main()
{
FILE *fp;

fp = fopen("[Link]", "w");

fprintf(fp, "Hello");

fclose(fp);

return 0;
}

Exam Writing Tip: First write definition, then syntax/program, then output and advantages.

You might also like