Submitted Questions

  • Output of these programs.

    {geshibot language="c"} struct Foo { char *pName; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName); } {/geshibot} a. Your Name b. compile error c. Name d. Runtime error {geshibot language="c"} struct Foo { char *pName; char *pAddress; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); obj->pName = malloc(100); obj->pAddress...

    wizard

    • Feb 27th, 2007

    In first case the mem is allocated for struct but not for pName. so you will get runtime error as "Segmentation fault".In second case also you will get the same, because here allocating memory and the...