pointers

#include<stdio.h>
int main()
{
int *a;
char *c;
*(a)=20;
*c=*a;
printf("%c",*c);
}



is the statement *c=*a wrong??
showing seg fault!

Comments

  • Welcome to the forum, preetham1992! ;)

    When a program seg faults repeatedly, you can be sure that it has a serious error. ;)

    Pointers hold addresses, (not numbers like 20). Both pointer assignments are incorrect.

    Try this:
    #include<stdio.h>
    int main()
    {
       int *a,num=100;
       char *c,ch='z';
       a=&num;
       c=&ch;
       printf("*a=%d, *c=%c \n",*a,*c);
       return 0;
    }
    
    What does the int pointer a hold as it's value?
    The address of num. (not 100).

    What does the char pointer c hold as it's value?
    The address of ch. (not 'z').
  • thanks a lot!! actually it was an interview question!!:)
Sign In or Register to comment.