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;}
Solution
The program prints "2".
Here's the step-by-step explanation:
-
An array
arrof 5 integers is declared and initialized with the values 1, 2, 3, 4, 5. -
A pointer
pis declared and initialized to point to the first element of the arrayarr. -
The pointer
pis incremented by 1. This means thatpnow points to the second element of the arrayarr. -
The value of the element pointed to by
pis printed. Sincepis pointing to the second element of the array, the value "2" is printed. -
The program returns 0, indicating successful execution.
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 )*
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.