Header Ads Widget

Ticker

6/recent/ticker-posts

pointer programs in C

  

COMPUTER GAYN


POINTER PROGRMS IN C LANGAUGE


Q1.print value veriable and address veriable using pointer?

Ans:-

#include<stdio.h>

int main()

{

            int a=10; // value variable a=10 and &a= address, *a = invalid

            int * ptr = &a; // ptr = address, &ptr = address ptr , *ptr= value at that address location

            printf("value of a = %d\n",a);

            printf("address of a variable = %u \n",&a);

//        printf("* a= %d",*a);

            printf("ptr = %u \n",ptr);

            printf("&ptr = %u \n",&ptr);

            printf("*ptr = %d\n ",*ptr);

            return 0;

}

 

 


click on link 👇👇👇👇👇👇👇

 Intel 660p Series SSDPEKNW512G8X1 512GB M.2 80mm PCI-Express 3.0 x4 Solid State Drive (QLC)

 

 

 

 

 

 

 

 

Q2. c program to print size of diffrent type of pointer veriable?

Ans:-

#include<stdio.h>

int main()

{

            int i;

            float f;

            double d; //value veriable

            char c;

           

            int *ip;

            float *fp;

            double *dp;//pointer type veriable

            char *cp;

printf("int size =%d \n",sizeof(i));

            printf("float size =%d \n",sizeof(f));

            printf("double size =%d \n",sizeof(d));

            printf("char size =%d \n",sizeof(c));

           

            printf("int * size =%d \n",sizeof(ip));

            printf("float * size =%d \n",sizeof(fp));

            printf("double * size =%d \n",sizeof(dp));

            printf("char * size =%d \n",sizeof(cp));

           

return0;

}

Q3. Write a program to print the elements of a 1D integer array along with  

        memory address of each element using pointer.

Ans:-

#include<stdio.h>

int main()

{

            int i;

           

            int a[5]={10,20,30,40,50};

            int *p = a;

            for(i = 0;i<=4;i++)

            {

                        printf("value= %d\n",a[i]);

                        p++;

            }

            return 0;

}

 

 

 

 

 

 

 

 

 

Q4. Write a program to print characters in string along with memory addresses

        of each character?

Ans:-

#include<stdio.h>

 

int main()

{

            int i;

            char *p;  // char pointer

            char name[10];

            printf("Enter any string \n");

            gets(name); // name="amol\0"

            p = &name[0]; // p = name;

            for(i=0; name[i]!= '\0';i++)

            {

                        printf("char %c having address %u \n",*p,p );

                        p++; //

            }

            return 0;

}

 

 

 

 

 

 

Q5. Swap two numbers using user defined “swap” function using   -call by

        Reference?

Ans:-

 

 

#include<stdio.h>

int main()

{

            int a,b;

            printf("enter the values of a and b \n");

            scanf("%d%d",&a,&b);

            swap(&a,&b);

           

}

int swap(int*m,int*n)

{

            int t;

            t=*m;

            *m=*n;

            *n=t;

            printf("after swapping,values of \na=%d \nb=%d",*m,*n);

            return 0;

}

Post a Comment

0 Comments