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 |
‎#define good bad main() { int good=1; int bad=0; printf ("good is:%d",good); }
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like.
21 Answers ABC, eBay, Goldman Sachs, Google, HUP, Microsoft, TATA,
write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details
main() { 41printf("%p",main); }8
String reverse with time complexity of n/2 with out using temporary variable.
#include<stdio.h> main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } }
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }
#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); }
How to access command-line arguments?
What is data _null_? ,Explain with code when u need to use it in data step programming ?
In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }