0% found this document useful (0 votes)
28 views8 pages

#Include Int Main (Void) (Int A 10, B 20, C Int P, Q P &a Q &B C P + Q Printf (" A %D B %D C %D/N", A, B, C) )

The document contains code snippets demonstrating the use of pointers and arrays in C programming. It includes examples of declaring and initializing pointer variables, dereferencing pointers to access array elements, passing pointers to functions, iterating through arrays using pointers, and a function to reverse a string by swapping characters using pointers.

Uploaded by

rhhsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views8 pages

#Include Int Main (Void) (Int A 10, B 20, C Int P, Q P &a Q &B C P + Q Printf (" A %D B %D C %D/N", A, B, C) )

The document contains code snippets demonstrating the use of pointers and arrays in C programming. It includes examples of declaring and initializing pointer variables, dereferencing pointers to access array elements, passing pointers to functions, iterating through arrays using pointers, and a function to reverse a string by swapping characters using pointers.

Uploaded by

rhhsa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

#include <stdio.

h>
int main(void)
{
int a=10, b=20, c;
int *p, *q;
p=&a; q=&b;
c = *p + *q;
printf(" a= %d b = %d c = %d\n", a, b, c);
}

#include <stdio.h>
int main(void)
{

int a=10, b=20;


int *p, *q, *r, *s;
p=&a; q=&b;
r=p ; s =q;
printf(" a=%d b =%d c=%d d=%d\n", *p, *q, *r, *s);

#include <stdio.h>
void function1(int a, int b);
void function2(int *p, int *q);
int main(void)
{
int a=10, b=20;
function1 ( a, b);
printf("After Calling function1, a = %d b = %d \n", a, b);
function2 ( &a, &b );
printf("After Calling function2, a = %d b = %d \n", a, b);
}
void function1(int a, int b)
{
a = 0;
b = 0;

return; }

void function2(int *p, int *q)


{
*p = 0; *q = 0;

return; }

#include <stdio.h>
int main(void)
{
int array[]={10,20,30,40,50};
int count;
for(count=0; count<5; count++)
printf("\n Index=%d Address=%x Value = %d\n",
count,
&array[count], array[count]);
}

Index=0 Address=bfe42cb0 Value = 10


Index=1 Address=bfe42cb4 Value = 20
Index=2 Address=bfe42cb8 Value = 30
Index=3 Address=bfe42cbc Value = 40
Index=4 Address=bfe42cc0 Value = 50

#include <stdio.h>
int main(void)
{
int array[]={10,20,30,40,50};
int count;
for(count=0; count<5; count++)
printf("\nIndex= %d
count,
}

Address= %x
array+count,

Value=%d",
*(array+count));

void swap (char *p, char *q)


{
char tmp = *p;
*p = *q;
*q = tmp;
}
int lengthstr(char *s)
{
int length;
for (length=0; *(s+length) != '\0'; ++length);
return length;
}

void reverse(char *s)


{
char tmp, *end;
end = s + lengthstr(s) - 1 ;
while (s < end ) swap (s++, end--);
}
int main( void )
{
char string[80];
scanf( "%s", string);
reverse( string );
printf( "%s\n", string);
return 0;
}

You might also like