Memory Allocation

Q1:
What will be the output of the program?
#include<stdio.h>
#include<string.h>

int main()
{
    char *s;
    char *fun();
    s = fun();
    printf('%s\n', s);
    return 0;
}
char *fun()
{
    char buffer[30];
    strcpy(buffer, 'RAM');
    return (buffer);
}

A 0xffff

B Garbage value

C 0xffee

D Error

ANS:A - 0xffff

The output is unpredictable since buffer is an auto array and will die when the control go back to main. Thus s will be pointing to an array , which not exists.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.