pointer and dyamaic memory
circular queue and queue program and pointer
#include<stdio.h>
#include<stdlib.h>
int main()
{ int i;
int *pr;
pr=(int *) calloc(1,sizeof(int));
if(pr==NULL)
{
printf("full");
exit(2);
}
for(i=1;i<6;i++)
{
*(pr+i)=i*2;
printf("%d\t",*(pr+i));
}
printf("%d",sizeof(*pr));
}
#include<stdio.h>
void fun(char a[],char b[])
{
printf("entrerd");
if(a==b)
printf("compare");
else
printf("govidha");
}
int main()
{
void (*ptr)(char[],char[]);
ptr=fun;
(*ptr)("suresh","reamesh");
// (*ptr)("suresh","suresh");
// printf("%u\n",fun);// it will give address
}
#include<stdio.h>
#include<stdio.h>
int add(int a,int b)
{
int sum=a+b;
return sum;
}
int sub(int a,int b)
{
int sum=a-b;
return sum;
}
int div(int a,int b)
{
int sum=a/b;
return sum;
}
int main()
{
int num;
scanf("%d",&num);
int a,b;
int (*ptr[3])(int ,int )={add,sub,div};
switch(num)
{
case 0:
printf("enter",scanf("%d%d",&a,&b));
printf("%d\n",(*ptr[0])(a,b));
break;
case 1:
printf("enter",scanf("%d%d",&a,&b));
printf("%d\n",(*ptr[1])(a,b));
break;
case 2:
printf("enter",scanf("%d%d",&a,&b));
printf("%d\n",(*ptr[2])(a,b));
break;
default: printf("govidha");
break;
}
}
#include<stdio.h>
int fun(int ff ,int ss)
{
int i,tt;
for(i=0;i<10;i++)
{
printf("%d",ff);
ff=ss;
ss=tt;
tt=ff+ss;
}
}
int main()
{
int f=0,s=1,t;
int (*ptr)(int ,int);
ptr=fun;
(*ptr)(f,s);
}
#include<stdio.h>
#include<stdlib.h>
struct emp
{
int roll;
int id;
char name[12];
};
int main()
{
struct emp *ptr;
ptr=(int *)malloc(sizeof(*ptr));
if(ptr==NULL)
{
printf("memory not allocated");
}
scanf("%d%s",&ptr->roll,ptr->name);
printf("%d",ptr->roll);
}
#include<stdio.h>
int pass(int *num);
int main()
{
int num1=5;
int *ptr=&num1;
pass(ptr);
}
int pass(int *a)//pointer to pointer mulitiplication not possible
//integer to pointer multi possible
{
int b=1;
int *fact=&b;
int num=*a;
while(num>0)
{
*fact=*fact*(num);
num--;
}
printf("%d",*fact);
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p=(int *)calloc(1,sizeof(int));
printf("%u\n",p);
if(p==NULL)
{
printf("can't ");
exit(2);
}
*p=100;
printf("%d\n",*p);
free(p);
printf("%d\n",*p);
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int (*p)[5]=(int(*)[])malloc(4*5*sizeof(int));
printf("%u\n",p);
if(p==NULL)
{
printf("can't ");
exit(2);
}
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
scanf("%d",&p[i][j]);
}
printf("\n");
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
printf("%d",p[i][j]);
}
printf("\n");
}
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p=(int *)malloc(5*sizeof(int));
if(p==NULL)
{
printf("can't ");
exit(2);
}
int i;
for(i=0;i<5;i++)
*(p+i)=i*2;
for(i=0;i<5;i++)
printf("%d\t",*(p+i));
printf("\n");
p=(int *)realloc(p,12);
for(i=0;i<3;i++)
*(p+i)=i*2;
for(i=0;i<3;i++)
printf("%d\t",*(p+i));
printf("\n");
free(p);
}
#include<stdio.h>
#include<stdlib.h>
int main()
{ int i;
int *p=(int *)malloc(8);
if(p==NULL)
{
printf("can't ");
exit(2);
}
for(i=0;i<5;i++)
{
*(p+i)=i*2;
printf("%d\n",*(p+i));
}
// p=(int *)realloc(p,0);
}
#include<stdio.h>
int main()
{
int a=12;
char ch='a';
float fl=10.23;
double dd=122.12;
int *ptr=&a;//de refernce pointer to integer then will get addres of integer
char *cha=&ch;
float *flot=&fl;
double *ddd=ⅆ //if any you will printf ddd then it will print addres of dd varible
printf("a=%d\ncha=%c\nflot=%f\nddd=%lf\n",*ptr,*cha,*flot,*ddd);// where the ptr addres hloder
//printf("%p",&ptr);// addre of pointer
printf("%d\n%d\n%d\n%d\n",sizeof(*ptr),sizeof(*cha),sizeof(*flot),sizeof(*ddd));
printf("%d\n%d\n%d\n%d\n",sizeof(ptr),sizeof(cha),sizeof(flot),sizeof(ddd));
}
#include<stdio.h>
int main()
{
int a=227;
int *ptr=&a;
ptr++;
//it wii increse addres value then itwill defult stack segment value
printf("ptr addres=%p\n",ptr);
printf("%d\n",*ptr);
// printf("%d\n%d\n%d\n%d\n",sizeof(*ptr),sizeof(*cha),sizeof(*flot),sizeof(*ddd));
char *ptr1=&a;
printf("%c",*ptr1);
}
#include<stdio.h>
int main()
{
int a=12,*ptr=&a;
int b=13,*ptr1=&b;
printf("%d\n",ptr1-ptr);// if i place %p it will give how it covert to bytes 0x1
printf("ptr=%p\nptr1=%p\n",ptr,ptr1);
}
#include<stdio.h>
//void pass(int *,int *);
int fact(int * );
int main()//program for pass by address
{
int a=5;
// int b=13;
// printf("beforea&b =%d\n%d\n",a,b);
// pass(&a,&b);
int aa=fact(&a);
printf("%d",aa);
// printf("%d\n%d\n",a,b);
}
//void pass(int *ptr,int *ptr1)
/*{
*ptr=*ptr+10;//refer pass by address
}*/
/*{//refer swap
int temp=*ptr;
*ptr=*ptr1;
*ptr1=temp;
}*/
int fact(int *n)
{
printf("%d",*n);
int f=12,s;
s=*n;
printf("%d",s);
while(s<=0)
{
f*=(s-1);
printf("%d",s);
}
return f;
}
#include<stdio.h>
int main()
{
int arr[]={23,34,45,35};
printf("%u\n",arr);//base addres
printf("%u\n",arr[0]);//base addres
printf("%u\n",arr[1]);//next address
printf("%u\n",arr+2);//increment address
printf("%d\n",*arr+2);//addtion value
printf("%d\n",*(arr+2));//access 2nd element
printf("%d\n",arr[-1]);
int *ptr=arr;
printf("%d\n",ptr);//it will hold base address of arry
printf("%d\n",ptr[1]);//arr 1
printf("%d\n",*(ptr+2));//arr 2
printf("%d\n",2[ptr]);//arr2
printf("%d\n",ptr=&arr[3]);//arr 3
ptr=&arr[3];
printf("%d\n",ptr[-1]);//
}
#include<stdio.h>
int main()
{
/*Note ptr will hold base charater and string*/
char str[]="cranes";
char *ptr=str;
printf("%c",++*ptr);
printf("%s\n",str);
printf("%s\n",ptr);
printf("%c\n",*ptr++);
printf("%c\n",*ptr);
printf("%C\n",--*ptr);
}
#include<stdio.h>
int main()
{
char str[]="india";
char *ptr=str;
printf("%s\n",ptr);
printf("%c\n",*ptr++);
printf("%s\n",ptr);
printf("%c\n",++*ptr);
printf("%s\n",ptr);
printf("%s\n",str);
}
#include<stdio.h>
int main()
{
char ch[]="suresh";
char *ptr=ch;
printf("address%u %u\n",ptr+2,ch+2);
printf("%s\n",ptr);
printf("%s\n",ch+2);
printf("%c\n",*ptr++);
printf("%c\n",*(ptr+1)+1);
printf("%s\n",ptr);
printf("%u %u\n",ch,ptr);
}
#include<stdio.h>
int main()
{
int arr[]={10,20,30,40,50,56,23,56,89};
int *ptr=arr;
int (*pptr)[5]=arr;
printf("base addres of arr&ptr %u %u\n",arr,ptr);
printf("pptr addres same %u\n",**(pptr+1));
printf("arr 1 st elent 10 :%d\n",*ptr);
printf("%d\n",*(ptr+6));//in single arry addres incre by adding 1
printf("%d\n",*(*(pptr)+1));
printf("base addres *pptr %u\n",*(*pptr+1));
printf("%d\n",*(ptr+1)+1);
printf("%d\n",(*ptr)++);
printf("%d\n",*ptr);
}
#include<stdio.h>
int main()
{
int arr[][3]={23,45,67,89,54,42,31};
int (*ptr)[3]=arr;
printf("%u\n",ptr[0]);//*(ptr+0)
printf("%d\n",*(*ptr));
printf("%d\n",*ptr[0]);
printf("%d\n",*(*ptr+1));
printf("ptr[0]+1 %d\n",ptr[0]+1);
printf("%u\n",&arr[0][1]);
printf("%d\n",*ptr+1);
printf("%d\n",*(*ptr+1));
printf("%u\n",&arr[0][1]);
printf("%d\n",arr[0][1]);//*ptr=arr[0][0]
//ptr+1=arr[1][0]
}
#include<stdio.h>
void fun(int arr[])
{
printf("%d\n",sizeof(*arr));
printf("%d\n",arr[0]);
}
int main()
{
int arr[][3]={23,45,67,89,54,42,31};
int (*ptr)[3]=arr;
printf("%d\n",sizeof(*arr));
int a[5]={1,2};
fun(a);
}
#include<stdio.h>
void printmat(int mat[][4])
{
printf("mat=%u\n",mat);//base address
printf("%u\n",mat+1);//1st row addres
printf("%u\n",*mat);//0 th row 0 coloum address
printf("%d\n",**mat);//access 0x0 element =1
printf("%u\n",**mat+1);//0 th row 2 element =2
printf("%u\n",*(*mat+1));//1 st row 0 colum =5
printf("%u\n",**(*mat+1));//1 st row 0 colum =5 next it will turn again address of same elemt (5)
}
int main()
{
int matrix[4]={{1,2,3,4},{5,6,7,8},{11,12,13,14},{3,4,5,6}};
printmat(matrix);
printf(" %u\n",matrix);
}
#include<stdio.h>
int main()
{
char *a[]={"world","erath","universe"};
char **ptr=a;
printf("%c\n",**(ptr+1));
printf("%s \n",(*(++ptr)+2));//if their is two stars means it acces single element
}
#include<stdio.h>
void fun(char *b[])
{
printf("%c\n",(*++*--b));
printf("%s\n",*++b+2);
}
int main()
{
char *a[]={"edit","search","file"};
fun(a+1);
}
#include<stdio.h>
int main()
{
char *a[]={"sam","search","file"};
char **p=a;
printf("%s\n",++*p);
printf("%s\n",*p++);
}
#include<stdio.h>
int main()
{
char str[]={"6pen","save","delete"};
char **ptr=str;
printf("%s\t %s\n",++*ptr,str);//increment ++*ptr
printf("%c\t %s\n",**ptr++,str);
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int* p;
printf("%p\n",p);
{
int x=12;
p=&x;
printf("%d\n",*p);
}
int y=23;
p=&y;
p=&x;
printf("%d\n",*p);
}
#include<stdio.h>
void pass(int []);
int main()
{
int arr[]={1,2,3,4};
pass(arr);
}
void pass(int arr1[])
{
printf("size %u\n",sizeof(arr1));
printf("arr 0 %d\n",arr1[0]);
printf("%p arr add\n",arr1);
arr1++;
printf("%p\n",arr1);
}
#include<stdio.h>
#include<string.h>
void pass(char[12]);
int main()
{
char arr[12];
printf("enter string ");
gets(arr);
puts(arr);
pass(&arr);
}
void pass(char *arr1)
{
int i,count=0,j=0;
puts(arr1);
printf("%d\n",sizeof(*arr1));
while(*arr1!='\0')
{
j++;
*arr1++;
}
for(i=1;i<=j;i++)
{
count++;
}
printf("strlength :%d/n",count);
}
#include<stdio.h>
int main()
{
int a=12;
int *ptr=&a;
int **ptrr=ptr;
printf("%u\n",ptrr);
printf("%u\n",*ptr);
printf("%u",**ptrr);
}
#include<stdio.h>
int sum(int *);
int main()
{
int num=12;
int *ptr=#
sum(&num);
}
int sum(int *num1)
{
int i=0;
for(;*num1!=0;*num1++)
{
printf("%d\t",i++);
}
}
#include<stdio.h>
void pass(int *);
int main()
{
int num;
int *ptr=#
printf("enter num");
scanf("%d",&num);
printf("%d\n",num);
pass(&num);
}
void pass(int *num1)
{
int n=*num1;
printf("n %d",n);
int i;
int fib[n];
fib[0]=0;
fib[1]=1;
for(i=2;i<=n;i++)
{
fib[i]=fib[i-2]+fib[i-1];
printf("%d\t",fib[i]);
}
}
#include<stdio.h>
void strcmpp(char str[]);
int main()
{
char name[]="suresh";
char *ptr=name;
strcmpp(name);
}
void strcmpp(char str[])
{
printf("%s\n",*str);
char *pptr=str;
if(*pptr==*str)
printf("compare");
else
printf("not");
}
#include<stdio.h>
#include<string.h>
int main()
{
char str[]="hello";
char *ptr=str;
printf("%c",++*ptr);
char *ptr1="suresh";//here it will read constant value that why you cannot modified
// printf("%c",++*ptr1);
ptr1++;
}
#include<stdio.h>
int main()
{
int a=12;
char ch='a';
float f=1.8;
double d=12.4;
char str[]="suresh";
void *vptr;
vptr =&a;
printf("%d\n",*(int *)vptr);
vptr =&d;
printf("%lf\n",*(double *)vptr);
vptr =&ch;
printf("%c\n",*(char *)vptr);
vptr =&f;
printf("%f\n",*(float *)vptr);
vptr=str;
printf("%s\n",(char *)vptr);
}
#include<stdio.h>
int main()
{
const int a=12;
int *ptr=&a;
int b=14;
*ptr=b;
printf("%d\n",a);
scanf("%d",&a);
printf("%d",a);
}
#include<stdio.h>
int main()
{
/*
int a=12,b=23;
const int *ptr=&a;
printf("%d\n",*ptr);
ptr=&b;
printf("%d",*ptr);*/
int a=12,b=23;
int *const ptr=&a;
*ptr=56;
printf("%d\n",*ptr);
// ptr=&b;//invalid because you cannt modifed addres
// error read-only
}
#include<stdio.h>
int main()
{
char *arr[]={"hello","suresh"};
char **pptr=arr;
printf("%u\n",pptr);//base of pointer to pointer
printf("%u\n",*pptr);// base addres of h
printf("%c\n",**(pptr+1));// secound name suresh
printf("%c\n",*(*pptr+1));//frist name frist elment h
printf("%c\n",*(*(pptr+1)+1));//pptr addre of elenent it will incresed addres of words
printf("%c\n",*(*(pptr+1)+1)+1);//pptr addre of elenent it will incresed addres of words
#include<stdio.h>
int sum(int);
int fact(int);
int fib(int);
int main()
{
int num=5;
int res=sum(num);
int res1=fact(num);
printf("%d\n%d\n",res,res1);
fib(num);
}//if your returning data u must store that in tempary varible
int sum(int n)
{
// printf("%d",n);
if(n==0)
{
// printf("%d",n);
return n;
}
else
{
n =n+sum(n-1);
return n;
}
}
int fact(int n1)
{
if(n1==1)
{
return n1;
}
else
{
n1= n1*fact(n1-1);
return n1;
}
printf("%d",n1);
}
int fib(int n2)
{
int st=0,sec=1,next,i=0;
if(n2==i)
{
printf("%d\t",st);
st=sec;
sec=next;
next=st+sec;
return fib(i+1);
}
}
#include<stdio.h>
int main()
{
struct ex
{
int a;
float f;
char ch;
//globle varibles s1&s
}s1,s;
printf("a=%d\n",s.a,scanf("%d",&s.a));
printf("f=%f\n",s.f,scanf("%f",&s.f));
printf("ch=%c\n",s.ch,scanf("%ch",&s.ch));
printf("a=%d\n",s1.a),scanf("%d",&s1.a);
printf("f=%f\n",s1.f),scanf("%f",&s1.f);
printf("ch=%c\n",s1.ch),scanf("%c",&s1.ch);
}
#include<stdio.h>
struct student
{
char name[100];
int roll;
float percent;
}s[10];
int main()
{
int i;
for (i=0;i<2;i++)
{
scanf("%s%d%f",&s[i].name,&s[i].roll,&s[i].percent);
}
for (i=0;i<2;i++)
printf("%s\t%d\t%f\n",s[i].name,s[i].roll,s[i].percent);
}
#include<stdio.h>
struct example
{
int a,b;
};
void fun(struct example);
int main()
{
struct example e={1,2};
fun(e);
}
void fun(struct example e1)
{
printf("%d\t%d\n",e1.a,e1.b);
}
#include<stdio.h>
struct example
{
int a,b;
};
void fun(struct example*);
int main()
{
struct example e={1,2};
fun(&e);//pASSING VALUE BY ADDRESS
}
void fun(struct example *e1)
{
printf("%d\t%d\n",e1->a,e1->b);
}
#include<stdio.h>
int main()
{
struct ex
{
int a;
struct inner
{
float f;
char ch;
}i;
}o={12,1.23,'w'};
printf("a=%d\t%f\t%c\n",o.a,o.i.f,o.i.ch);
}
#include<stdio.h>
#pragma pack(1)
int main()
{
struct ex
{
double dd;//note:it will check only cycle not in bits in struct and unions
int a;//4 bytes
//float f;//4 bytes
char ch;//1 byte waste 3 bytes
// int z;//4 bytes
}s;//structure padding
printf("a=%d\n",sizeof(s));
}
#include<stdio.h>
struct ex
{
struct ex a;//invallid
struct ex *s;//vallid where pointer act like own data type member
}
#include<stdio.h>
#pragma pack(1)
int main()
{
union ex
{
double dd;//note:it will check only cycle not in bits in struct and unions
int a;//4 bytes
float f;//4 bytes
char ch;//1 byte waste 3 bytes
int z;//4 bytes
};
union ex e;
e.dd=123.44;
printf("%0.2lf\n",e.dd);
printf("a=%d\n",sizeof(e));
}
#include<stdio.h>
enum week
{
mon,tue,wed=14,fri='a',sat,sun
};
int main()
{
printf("%d\n",mon);
printf("%d\n",tue);
printf("%d\n",wed);
printf("%d\n",fri);
printf("%d\n",sat);
}
#include<stdio.h>
typedef int num;
num a=12;
num b=13;
int main()
{
printf("%d%d\n",a,b);
}
#include<stdio.h>
typedef int num[10];
int main()
{
num a,b;
printf("%d\n",sizeof(a));
num c[5];
printf("%d\n",sizeof(c));
}
#include<stdio.h>
typedef int fun (int ,int);
fun sum,sub;
//advantages of typedef simply the code and using own key words
int main()
{
printf("%d\n",sum(3,4));
printf("%d\n",sub(6,4));
}
int sum(int a,int b)
{
return a+b;
}
int sub(int a,int b)
{
return a-b;
}
#include<stdio.h>
typedef struct example
{
int a,b;
}s;
void fun(s);
int main()
{
s e={1,2};
fun(e);
}
void fun(s e1)
{
printf("%d\t%d\n",e1.a,e1.b);
}
#include<stdio.h>
struct emp
{
unsigned int a:3;
unsigned int b:4;
unsigned int c:3;
unsigned int d:4;
}s1={2,12,7,12};
int main()
{
printf("%d %d %d %d\n",s1.a,s1.b, s1.c ,s1.d);
printf("%d\n",sizeof(s1));
}
#include<stdio.h>
struct emp
{
int a:3;
int b:4;
int c:3;
int d:4;
}s1={2,12,7,12};
int main()
{
printf("%d %d %d %d\n",s1.a,s1.b, s1.c ,s1.d);
printf("%d\n",sizeof(s1));
}
#include<stdio.h>
int main(int argc,char* argv[])
{
int i;
printf("%d\n",argc);
for(i=0;i<argc;i++)
{
printf("%s\n",argv[i]);
}
}
#include<stdio.h>
int main(int argc,char* argv[])
{
int i;
printf("%d\n",argc);
for(i=0;i<argc;i++)
{
printf("%d\n",atoi(argv[i]));
}
}
#include<stdio.h>
#define size 5
int arr[5];
int top=-1;
int push(int );
int pop(int );
void display();
int main()
{
display();
push(10);
push(10);
push(10);
push(120);
push(13);
pop(10);
int n=pop(120);
printf("%d",n);
//push(23);
}
int push(int ele)
{
if(top==size-1)
{
printf("stack full");
return;
}
top++;
arr[top]=ele;
}
int pop(int ele)
{
if(top==-1)
{
printf("stack empty");
return -1;
}
ele=arr[top];
top--;
printf("%d",ele);
return ele;
}
void display()
{
if(top==-1)
{
printf("stack sir empty");
return;
}
int i;
for(i=top;i>=0;i--)
{
printf("%d\n",arr[i]);
}
printf("\n");
}
#include<stdio.h>
#define sz 5
int top=-1;
int stock[sz];
void push(int ele)
{
if(top==sz-1)
{
printf("stack full\n");
}
else
{
top++;
stock[top]=ele;
printf("push stock:%d\t",stock[top]);
printf(" push top : %d\t",top);
}
}
int pop()
{
if(top==-1)
{
printf("stack is empty in pop\n");
}
else
{
top--;
stock[top];
printf("top : %d\t",top);
}
return top;
}
void peek()
{
if(top==-1)
{
printf("stack empty in peek");
}
else
{
printf("stock peek :%d\n",stock[top]);
}
}
void transver()
{
if(top==-1)
{
printf("stock empty in transver\n");
}
int i;
for(i=0;i<=top;i++)
{
printf("in transever %d\t",stock[i]);
}
}
int main ()
{
push(12);
push(23);
pop();
peek();
transver();
}
#include<stdio.h>
#define sz 5
int top=-1;
int stock[sz];
void push(int ele)
{
if(top==sz-1)
{
printf("stack full\n");
}
else
{
top++;
stock[top]=ele;
printf("push stock:%d\t",stock[top]);
printf(" push top : %d\t",top);
}
}
int pop()
{
if(top==-1)
{
printf("stack is empty in pop\n");
}
else
{
top--;
stock[top];
printf("top : %d\t",top);
}
return top;
}
void peek()
{
if(top==-1)
{
printf("stack empty in peek");
}
else
{
printf("stock peek :%d\n",stock[top]);
}
}
void transver()
{
if(top==-1)
{
printf("stock empty in transver\n");
}
int i;
for(i=0;i<=top;i++)
{
printf("in transever %d\t",stock[i]);
}
}
int main ()
{
printf("1. enter 1 push()\n");
printf("2. enter 2 pop()\n");
printf("3. enter 3 peek()\n");
printf("4. enter 4 transver()\n");
int num;
printf("enter num of operation \n");
scanf("%d",&num);
switch(num)
{
case 1:
printf("enter value\n");
int value;
scanf("%d",&value);
push(value);
break;
case 2:
pop();
break;
case 3:
peek();
break;
case 4:
transver();
break;
default:
printf("your enter not in range");
}
}
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* right;
struct node* left;
};
struct node* root=NULL;
void insert()
{
struct node *p,*t;
t=(struct node*)malloc(sizeof(struct node));
printf("enter data\n");
scanf("%d",&t->data);
t->right=NULL;
t->left=NULL;
if(root==NULL)
{
root=t;
}
else
{
struct node* current;
current=root;
while(current)
{
if(t->data>current->data)
{
current=current->right;
}
else
{
current=current->left;
}
p=current;
}
}
}
void delete0cheild()
{
struct node *current,*p;
current=root;
while(current)
{
p=current;
current=current->right;
}
if(current->right==NULL&¤t->left==NULL)
{
current->data=NULL;
}
free(current);
}
int main()
{
insert();
insert();
insert();
insert();
insert();
insert();
delete0cheild();
}
#include<stdio.h>
#include<string.h>
//void fun(const char*);
char *join(char *,char*);
int main()
/*{
char *a[]={"cranes","varsity"};
char **b=&a[1];
printf("%c\n",(*++*--b));//(++(*(--b)))-b=102->*(++*(100))-->*(++cranes)-->result r
}
{
char*str[]={"open","save","delete"};
char **ptr;
ptr=str;
printf("ptr=%s str=%s\n",++*ptr,*str);//++(*ptr)-->pen open
printf("ptr=%s str=%s\n",*ptr++,*str);//post increment not effected
printf("ptr=%s str=%s\n",*ptr,*str);
}
{
const char *p="hello";
fun(p);
return(0);
}
void fun(const char *s)
{
printf("%d\n",is[6]);
char *q=s+6;//constant we cont chage values but we can chage address
char *p=&s[6];
++p;
printf("%d\n",p-q);
++p;
printf("%d\n",p-q);
}
{
int a=0xfd;
int *p,*q,*r;
p=q=&a;
a=++*q;
r=(char*)&a;
printf("%x%x\n",*r,a);
}*/
// char *join(char *,char*);
{
printf("%s\n",join("c++","programming"));
}
char *join (char *s1,char *s2)
{
#define MAXBUF 32
char buf [MAXBUF];
strcat(strcpy(buf,s1),s2);
printf("buf=%s",buf);
return buf;
}
Comments
Post a Comment