Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

C Program Basic

Basic knowledge about c programming language

Uploaded by

Pes 2000
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 views

C Program Basic

Basic knowledge about c programming language

Uploaded by

Pes 2000
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
You are on page 1/ 3

Variables

Syntax : dataType variable_name; -Without


Initialisation
dataType variable_name = value; -With Initialisation

Initialisation - Giving a value to a variable at declaration.

eg : int num;
int num=45;

DataTypes in C

DataType Example Variable Value Type


int eg: int a=2; numbers
float/double eg: float pi=3.14 decimal point numbers
char eg: char b='a' single
character(text/num/symbols)

Array in C

Declaring an Array
Syntax: array_name[size];
or
Syntax: array_name[size]={x1,x2,...,xn};

eg: Size[]={500,200,100,50,20,10,5,2,1};

Basic C Input/Output Functions

#include<stdio.h> - Calls Standard Library header files

scanf(); function
scanf(); function is used to read input value to a variable from the user

Syntax: scanf("dataType",&variable_name);
eg: scanf("%d",&num);

printf(); Function
printf(); function is used to display or output value inside () from the program

Syntax: printf("info to print"); - Displays value inside ()


eg: printf("Hello world"); - Prints Hello World in terminal

int a=20;
printf("%d",a); - Prints value of a which is 20

Some Basic DataTypes used inside scanf(); and printf(); functions:

%d - Integer int
%f - Float float
%lf - Long Float double
%c - Character char
%s - String str

Basic C Program Structure

#include<stdio.h> //- Header Files

int main() or void main() //- Main Function


{
int a,i=10; //- Declaring variables
printf("Enter a number :"); //- Prints statement between " "
scanf("%d",&a); // - Reads a value for variable a of integer type, hence
"%d"

printf("%d * 10 = %d", a, a*i); // -Prints value of a and product of a*i

return 0; //- only used at end of int main()


}

for loop (Entry Controlled)

syntax: for(a=value;a<b;a++)
{
statements;
}

eg: for(i=0;i<10;i++)
{
printf("%d",i);
}

while loop (Entry Controlled)

syntax: while(condition statement)


{
statements;
}

eg: i=0;
while(i<10)
{
printf("%d",i);
i++;
}
Recursion : Calling a function within the same function itself

You might also like