Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

The output of the code will be 4.

Here's the step by step explanation:

  1. An integer array arr[] is declared and initialized with the values {1, 2, 3, 4, 5}.

  2. A pointer *p is declared and it is pointed to the base address of the array arr[]. So, p is pointing to the first element of the array, which is 1.

  3. In the printf statement, *(p + 3) is used. Here, p + 3 means the address of the 4th element in the array (since array indexing starts from 0). So, *(p + 3) is the value at the address p + 3, which is the 4th element of the array arr[].

  4. Therefore, 4 is printed as the output.

This problem has been solved

Similar Questions

What will be the output of the following code snippet?

What is the output of the following code in Python?

What will be the output of the following C code?

What is the output for the following code?Note: This question helps in clearing conceptual technical interviews for service-based companies.

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.