Knowee
Questions
Features
Study Tools

What is the output of this program?#include <stdio.h> int main() {  int arr[5] = {1, 2, 3,4,5};  int p, q, r;  p = ++arr[1];  q = arr[1]++;  r = arr[p++];  printf("%d, %d, %d", p, q, r);  return 0; }

Question

What is the output of this program?#include <stdio.h> int main() {  int arr[5] = {1, 2, 3,4,5};  int p, q, r;  p = ++arr[1];  q = arr[1]++;  r = arr[p++];  printf("%d, %d, %d", p, q, r);  return 0; }

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of this program is "3, 2, 4".

Here is the step-by-step explanation:

  1. The program declares an integer array arr with 5 elements and initializes it with the values {1, 2, 3, 4, 5}.
  2. Three integer variables p, q, and r are declared.
  3. p is assigned the value of ++arr[1]. This means that the value of arr[1] is incremented by 1 before being assigned to p. So, p becomes 3.
  4. q is assigned the value of arr[1]++. This means that the value of arr[1] is assigned to q and then incremented by 1. So, q becomes 2.
  5. r is assigned the value of arr[p++]. This means that the value of arr[p] is assigned to r and then p is incremented by 1. Since p is 3, arr[3] is 4, so r becomes 4.
  6. The program prints the values of p, q, and r using the printf function. So, the output is "3, 2, 4".

This problem has been solved

Similar Questions

What will be the output of the following program?

What is the output of the following C Program?

What is the output of the following Java program?

What is the output for the following code?

what will be the output of the c program?

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.