Knowee
Questions
Features
Study Tools

Consider the following code. What will be the output?#include <stdio.h>int main() {    int arr[3] = {10, 20, 30};    int *p = arr;    *(p + 1) = 40;    printf("%d\n", arr[1]);    return 0;}

Question

Consider the following code. What will be the output?#include <stdio.h>int main() {    int arr[3] = {10, 20, 30};    int *p = arr;    *(p + 1) = 40;    printf("%d\n", arr[1]);    return 0;}

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

Solution

The output will be 40.

Here's the step by step explanation:

  1. An integer array arr of size 3 is declared and initialized with the values 10, 20, and 30.

  2. A pointer p is declared and initialized to point to the first element of the array arr.

  3. The statement *(p + 1) = 40; changes the value of the second element in the array arr to 40. This is because p + 1 points to the second element of the array (since array indexing starts from 0), and * is used to dereference the pointer, i.e., access the value pointed by the pointer.

  4. The printf statement prints the value of the second element of the array arr, which is now 40.

So, the output of the program will be 40.

This problem has been solved

Similar Questions

What will be the output of the following code snippet?

What is the output for the following code?

What will be the output of the following C++ code?

What will be the output of the following program?

What will be the output of the following C code?

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.