What is the output of the following C programming language code? #include<stdio.h> int main() { int x = 10; int *p = &x; *p = *p + 5; printf("%d %d", x, *p); return 0; }
15 15
To determine the output of the given C code, let's go through it step by step:
#include<stdio.h>
int main()
{
int x = 10;
int *p = &x;
*p = *p + 5;
printf("%d %d", x, *p);
return 0;
}
<stdio.h>, which is essential for using the printf function.main function, an integer variable x is initialized with the value 10.p is created and initialized with the address of x using the address-of operator &.*p = *p + 5; is executed. Here, *p dereferences the pointer, accessing the value of x. Thus, *p + 5 results in 10 + 5 = 15. This value is then assigned back to x through the pointer.printf("%d %d", x, *p); function call prints the values of x and *p. Since *p is still pointing to x, both x and *p print the value 15.Therefore, the output of this code will be 15 15.
Conclusion: The correct answer is 15 15. This confirms that the pointer p successfully modified the value of x to 15, and both x and *p reflect this change.
Consider the following ANSI-C program.
#include <stdio.h>
int main(){
int *ptr, a, b, c;
a=5; b=11; c=20;
ptr=&a; *ptr=c; ptr=&c;
a=*(&b); c=*ptr-a;
printf("%d",c);
return(0);
}
The output of this program is ____________. (answer in integer)
Note: Assume that the program compiles and runs successfully.
What is the output of the following program ?
(Assume that the appropriate preprocessor directives are included and there is no syntax error)
main ( )
{ char S[ ]="ABCDEFGH";
printf ("%C", * (& S[3]));
printf ("%s", S+4);
printf ("%u", S);
/* Base address of S is 1000 */
}