Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

The program prints "2".

Here's the step-by-step explanation:

  1. An array arr of 5 integers is declared and initialized with the values 1, 2, 3, 4, 5.

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

  3. The pointer p is incremented by 1. This means that p now points to the second element of the array arr.

  4. The value of the element pointed to by p is printed. Since p is pointing to the second element of the array, the value "2" is printed.

  5. The program returns 0, indicating successful execution.

This problem has been solved

Similar Questions

What will print out when the following code runs?

What will be the output of the following program?

What is the output of the following program :print "Hello World"[::-1]

What is the output for the following code?

What does the program below display?full_name = "Jane"full_name = full_name   + "Brown"print( full_name  )*

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.