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 C program:
#include <stdio.h>
void stringcopy(char *, char *);
int main(){
char a[30] = "@#Hello World!";
stringcopy(a, a + 2);
printf("%s\n", a);
return 0;
}
void stringcopy(char *s, char *t) {
while(*t)
*s++ = *t++;
}
Which ONE of the following will be the output of the program?
Consider the following C program:
#include <stdio.h>
int main(){
int a;
int arr[5] = {30,50,10};
int *ptr;
ptr = & arr[0] + 1;
a = *ptr;
(*ptr)++;
ptr++;
printf("%d", a + (*ptr) + arr[1]);
return 0;
}
The output of the above program is ____________ (Answer in integer)
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.