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 |
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }
What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100); assert(s != NULL); return s; }
write a program in c to merge two array
main() { int i = 100; clrscr(); printf("%d", sizeof(sizeof(i))); } a. 2 b. 100 c. 4 d. none of the above
#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr, int)); }
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.
Write a program that find and print how many odd numbers in a binary tree
main() { int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p } a. Runtime error. b. 1.00000 c. Compile error d. 0.00000
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }
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
how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns
Find the largest number in a binary tree