Predict the Output:
int main()
{
int *p=(int *)2000;
scanf("%d",2000);
printf("%d",*p);
return 0;
}
if input is 20 ,what will be print
Answers were Sorted based on User's Feedback
Answer / vadivelt
Result:
Ans1.It prints the input given
Ans2.Program Crashes
Why Ans1?
--
1.If the memory 2000 is not a system or read only location
and if it is not a address of other constant varible which
is assigned by the compiler, then the input is stored in
the location. And it will be fetched in the prinf()
statement using *p and ll be printed.
Why Ans2?
--
In this program the pointer *p, does not holds the address
of a variable for which memory is allocated(may be static
or dynamic).Instead blindly it holds the address 2000.
The address may contain.
1.System files(OS) or
2.It may be a location from read only memory.
So, when we are trying to get input value and store it in
the location 2000, using scanf(), it may try to overwrite
the data in system file location or read only memory.
So the program Ultimately has to crash.
Is This Answer Correct ? | 7 Yes | 0 No |
How to reverse a String without using C functions ?
33 Answers Matrix, TCS, Wipro,
Write a program to receive an integer and find it's octal equivalent. How can i do with using while loop.
What is the main difference between STRUCTURE and UNION?
main() { int i; i = abc(); printf("%d",i); } abc() { _AX = 1000; }
main() { char *p = "hello world"; p[0] = 'H'; printf("%s", p); } a. Runtime error. b. “Hello world” c. Compile error d. “hello world”
plz send me all data structure related programs
WAP to display 1,2,3,4,5........N
plz send me all data structure related programs
What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }
Code for 1>"ascii to string" 2>"string to ascii"
1 Answers Aricent, Global Logic,
how many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!
write a program for area of circumference of shapes