What will be the output of the following C code?#include<stdio.h>
void main() {
int arr[5] = {10,20,30,40,50};
int *p = (int*)(&arr + 1);
printf("%d %d", *(arr+1), *(p-1));
}
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. 20 50
Explanation
*(arr + 1) = arr[1] = 20. &arr + 1 points just past the whole array, so p − 1 points to the last element, 50.More Programming Languages and Computer Graphics questions
- Find the output of the following code:#include<stdio.h> void main() { int arr[] = {1, 2, 3, 4, 5}; int *p = arr; printf("%d", *p++); printf…
- Consider a triangle PQR with coordinates P(0,0), Q(2,2) and R(10,4). If this triangle is to be magnified to four times its size while keepi…
- Which of the following statements is TRUE?
- What is the output of the following program?#include<stdio.h> int main() { int i = 3; while (i--) { int i = 10; i--; printf("%d", i); } pri…
- The hue of a colour is related to its:
- What is the output of the following program?#include <stdio.h> #define SQR(x) (x*x) int main() { int a, b = 3; a = SQR(b+2); printf("%d", a…