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 |
main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above
main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }
main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above
#define a 10 int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } void foo() { #undef a #define a 50 }
typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }
4. Main() { Int i=3,j=2,c=0,m; m=i&&j||c&I; printf(“%d%d%d%d”,I,j,c,m); }
given integer number,write a program that displays the number as follows: First line :all digits second line : all except the first digit . . . . Last line : the last digit
Program to find the largest sum of contiguous integers in the array. O(n)
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() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
6 Answers Fusion Systems GmbH,
Print an integer using only putchar. Try doing it without using extra storage.