You are on page 1of 9

C PROGRAMMING

BY MOHAMMED TAJUDDIN
C PROGRAMMING
Array ascending order :
#include<stdio.h>
int main(){
int a[5]={9,6,3,1,4},i,j,temp;
printf(“array ascending order is\n”);
for(i=0;i<5;i++){
for(j=i+1;j<5;j++){
if(a[i]>a[j];{
temp=a[i];
a[i]=a[j];
a[j]=temp;}}}
C PROGRAMMING
for(i=0;i<5;i++)
{
printf(“%d\n”,a[i]);
}
return 0;
}
}
C PROGRAMMING
#include<stdio.h>
int main(){
int a[5]={2,8,1,9,4};
int i,max;
printf(“maximum value in array is”);
max=a[0];
for(i=1;i<5;i++)
if(a[i]>max
max=a[i];
printf(“%d\n”,max);
return 0;}
C PROGRAMMING
Two Dimentional Array :
#include<stdio.h>
int main(){
int a[4][3]={1,2,3,4,5,6,7,8,9,10,11,12};
int r,c;
printf(“two dimentional array is\n”);
for(r=0;r<4;r++){
for(c=0;c<3;c++){
printf(“%d”,a[r][c]);}
printf(“\n”);}
return 0;
}
C PROGRAMMING
Pointers :
The pointer in C language is a variable which stores the address of
another variable. This variable can be of type int, char, array, function,
or any other pointer. The size of the pointer depends on the
architecture. However, in 32-bit architecture the size of a pointer is 2
byte.
C PROGRAMMING
#include <stdio.h>
int main(){
int* p, c;
c = 22;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c); // 22
pc = &c;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc); // 22
c = 11;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc); // 11
*pc = 2;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c); // 2
return 0;
}
C PROGRAMMING
Function Pointer :
#include<stdio.h>
int sum(int,int);
intmain(){
int s=0;
int (*ptr)(int,int)=&sum;
s=(*ptr)(10,20);
printf(“%d\n”,s);}
int sum(int a,int b){
return (a+b)}
C PROGRAMMING
Array of Poiters :
#include<stdio.h>
int main(){
int* p[5];
int i;
for(i=0;i<5;i++)
{
p[i]=&a[i];
printf(“%p\n”,p[i]);
}

You might also like