What is C Language ?
Ans:- C is a middle Level procedural oriented Programming language developed by Dennis Ritchie in 1972.
- it is widely used in the software development field.
- it is a procedure and structure oriented language.
- it has the full support of various operating systems and hardware platforms.
- A compiler compiles the source file and generates an object file.
- A Linker Links all the object Files together and creates one executable file.
- it is highly portable.
Syntax of C :-
#include<stdio.h>
#include<conio.h>
Void main ();
{
..................................
..................................
Statement:
getcg();
}
Print the message.
#include<stdio.h>
#include<conio.h>
void main();
{
Printf(" My Name Randhir Kumar");
getcg();
}
- Short cut key for the Compile the Written the Program is
- Short cut key for the Run the Written the Program is
Output :-
My Name Randhir Kumar
- Printf() :- The printf() function is used to print the output of program on the standard output device.
- Scanf() :- The Scanf() function is used to take input from the used from a standard input device.
Ans:- Keyword is a Reserved word / Predefined word whose meaning already defined in the compiler.
Note :- There are 32 keywords in programming language.
Int extern for Sizeof
char go to const short
float break if struct
double continue else union
void do Enum typedef
auto switch signed volatile
register case unsigned default
return while static long
What is Data types?
Data type specifies the size & type of values that can be stored in a variable.
There are two types of datatype
- Primary data types
- Secondary datatype
- Primary datatype :-
- Secondary Datatypes :-
Size of primary datatype
- int ( 2 byte & -32768 to +32767 )
- char ( 1 byte & -128 to +127 )
- float ( 4 byte & 1.175 E -38 to 3.4 E+38 )
- Double ( 8 byte )
- Void ( 0 byte )
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
printf( "%d", size of unit);
getch();
}
Example :-
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10;
clrscr();
printf( "%d", size of unit);
getch();
}
Output :-
is 10
- #include<stdio.h>#include<conio.h>void main(){int a=10.50;clrscr();printf( "%f", size of unit);getch();}
Output :-
is 10.50 What is Variable ?
Ans- Variable is the name of memory location where we Store data.
Types of variable :-
- Local variable
- Global variable
- Static Variable.
# include<stdio.h>
#include<conio.h>
int a; // global variable
void main()
{
int b ; // local variable
Static int c; // static variable
clrscr();
printf("d%", a); // 0
printf("d%", b); // garbage
printf("d%", c); // 0
getch();
}
- Local Variable is default value is = garbage
- Global variable is default value is = 0
- Static variable is default value is = 0
Ans- Identifier refers to the name that is used to identifier variables functions and so on .
For Example :- int a; , int b;
void fun; , void fum;
What is operator?
Ans :- Operator is a symbol that tells the compiler to perform mathematical and logical task.
Types of operator :-
- Arithmetic operator :- ( + , - , * , / , %)
- Relational operator :- (< , > , <= , >= , == , /= )
- Logical operator :- ( & , && , !! , !)
- Increment / Decrement ( ++ , --)
- Pre Increment / Pre Decrement ( ++a , --a )
- Post Increment / Post Decrement ( a++ , a--- )
- Ternary operator ( ?! )
- Assignment operator ( = )
#include<stdio.h>
#include<conio.h>
void main()
{
int 10;
clrscr();
printf("%d \n", a); // 10
printf("%d \n", ++a); // 11
printf("%d \n", --a); // 11
printf("%d \n", a++); // 12
printf("%d \n", a--); // 11
` printf("%d \n", a); // 10
Ternary operator used for c programming
#include<stdio.h>
#include<conio.h>
void main()
{
int a = 50 , b = 20 ;
clrscr();
printf( " %d \n " , ( a > b ) ? a : b );
getch();
}
Output is = 50
- FILogical operator :-
#include< stdio.h>
#include< conio.h>
void main ()
{
int a = 50 , b = 20 ;
clrscr();
printf( " %d \n " , ( a>b ) && ( a < b )); // 0
printf( " %d \n " , ( a>b) !! ( a<b)); // 1
printf( " %d \n " , ( a>b )); // 0
getch();
}
CONDITIONAL STATEMENT :-
- IF Statement.
- IF -Else Statement.
- IF-Else-IF Statement.
- Nested IF Statement.
- Switch Statement.
* what is if statement. :-
Ans:- If statement is used when we want to test a condition.
Syntax :-
if( condition )
{
// Statement ;
}
Write a program to show the example of if Statement?
#include<stdio.h>
#include<conio.h>
void main()
{
int password;
clescr();
printf(" Enter a password \n");
Scanf("%d",&password);
if( password == 23123)
{
printf("Welcom \n");
}
printf(" main function ended");
getch();
}
Output :-
Enter a passward 23123
Welcome
Main function ended
What is if-else Statement?
Ans:- if is used to execute two statement either if statement or else statement for a single condition.
Syntax :-
if ( condition )
{
// statement 1;
}
else
{
// statement 2;
}
Write a program to check a person is eligible for vote or not ?
Algorithm :-
Step 1 : start
Step 2 : input age
Step 3 : if age greater 18 then
print " vote "
other wise
print " not "
Step 4 : Stop
#include<stdio.h>
#include<conio.h>
void main()
{
int age;
clrscr();
printf(" Enter the age = \n");
scanf( "%d",&age);
if( age>=18)
{
printf( "Eligible for vote");
}
else
{
printf( "not Eligible for vote:);
}
getch();
}
Outeput :-
Enter the age = 18
Eligible for vote
Enter the age = 15
not Eligible for vote
Enter the age = 25
Eligible for vote
What is if else-if Ladder Statement
Ans :- if else if statement used when we have multiple ( more than two ) conditions.
Syntax :-
if ( candition 1 )
{
Statement 1
}
else if ( candition 2)
{
Statement 2
}
else
{
Statement 3
}
Write a program to check student Result.?
#include<studio.h>
#include<conio.h>
void main()
{
int marks;
clrscr();
printf( "Enter the marks = \n");
scanf("%d", &marks);
if ( marks ==100 )
{
printf( "Ginius");
}
else if ( marks>=80 && marks<100)
{
printf( " Topper");
}
else if ( marks>=60 && marks <=79)
{
printf( "First");
}
else
{
printf( " Average Student ");
}
getch();
}
Output :-
Enter the marks = 100
Ginius
Enter the marks = 80
Topper
Enter the marks =60
First
Enter the marks = 40
Average Student
* What is nested if - else Statement.?
Ans :- Whenever we define if else block inside another if else block called nested if else Statement.
* Syntax :-
if ( condition 1 )
{
if ( condition 2 )
{
Statement 1;
}
else
{
Statement 2;
}
}
else
{
if (condition 3)
{
Statement 3;
}
else
{
Statement 4;
}
}
For Example :-
#include<stdio.h>
#include<conio.h>
void main()
{
int a=10,b=5,c=50;
clrscr();
if(a>b)
{
if(a>c)
{
printf( "%d",a);
}
else
{
printf("%",c);
}
}
else
{
if(b>c)
{
printf("%d",b);
}
else
{
printf("%d",c);
}
}
getch();
}
What is Switch Statement?
Ans:- Switch Statement used when we want to select any one case out of multiple cases.
Syntax :-
Switch ( exp )
{
case 1: Statement;
break;
case 2: Statement;
break;
default: Statement;
break;
}
* Write a program to perform arithmetic operation using switch case.?
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
int Ch;
printf( " ENTER THE NUMBER");
scanf( "%d %d",&a,&b);
printf( "Enter the choice");
scanf("%d",&Ch);
Switch (Ch)
{
case 1:
c = a + b;
printf("%d",&c);
break;
case 2:
c = a - b;
printf("%d",&c);
break;
case 3:
c = a * b;
printf("%d",&c);
break;
case 4:
c = a / b;
printf("%d",&c);
break;
default;
printf( "id choice ");
}
getch();
}
Output :-
ENTER THE NUMBER
= 56
= 89
Enter choice 1
sumr = 145
* What is Loops :-
Ans:- Loops is used to repeat a block of code until the given condition is true.
Types of Loops?
- While Loops.
- do while Loops.
- for Loops.
* While loops :-
Syntax :-
While ( condition )
{
// Statement;
}
* Print the n1 to 10 number .?
#include<stdio.h>
#include<conio.h>
void main(0
{
int i = 1;
clrscr();
while( i<=10)
{
printf( "%d",i);
++i;
}
getch();
}
Output :-
1,2,3,4,5,6,7,8,9,10
DO While Loops.?
Syntax :-
do
{
Statement;
}
while ( condition );
* print the natural number 1 to 10 .?
#include<stdio.h>
#include<conio.h>
void main ()
{
int i=1;
clrscr();
do
{
printf( "%d\n",i);
++i;
}
while( i<=10);
getch();
}
Output :-
1,2,3,4,5,6,7,8,9,10
For Loops:-
Syntax :-
for( Intialization ; Condition ; Increment )
{
Statement;
}
* How to print the natural number 1 to 10.?
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for( i=1;i<=10;i++)
{
printf("%d\n",i);
}
getch();
}
Output :-
1,2,3,4,5,6,7,8,9,10
What is nested loop ?
Ans :- A LOOPS WHICH CONTAIN INSIDE ANOTHER LOOP CALLED NESTED LOOP.
Syntax :-
for ( Initialization ; Condition ; Increment / Decrement)
{
for ( Initialization ; Condition ; Increment / Decrement)
{
Statement;
}
}
* Saine stare print.?
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for( i=1;i<=5;i++)
{
for( j=1;j<=i;j++ )
{
printf("*");
}
printf("\n");
}
getch();
}
Output :-
*
* *
* * *
* * * *
* * * * *
* Jumping Statement :-
- Break
- Cantinue
- exit
- goto
- Return
1) Break Programming.