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)
Let's analyze the given C program step by step:
int arr[5] = {30,50,10};arr with the first three values as 30, 50, and 10. Remaining elements are initialized to 0.int *ptr;ptr of type integer.ptr = & arr[0] + 1;ptr to point to arr[1]. Initially, arr[0] is 30, and arr[1] is 50, so ptr now points to the value 50.a = *ptr;ptr (50) to a, so a = 50.(*ptr)++;ptr (which is arr[1]) by 1, changing the value from 50 to 51.ptr++;ptr so that it now points to arr[2], which is initially 10.printf("%d", a + (*ptr) + arr[1]);a + (*ptr) + arr[1]:
a is 50.*ptr now points to arr[2], which is 10.arr[1] was incremented to 51.The final expression becomes 50 + 10 + 51 = 111.
The computed result, 111, fits within the specified range (111, 111).
Therefore, the output of the program is 111.
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 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.