arrow
arrow
arrow
#include<stdio.h> void main() { int arr[] = {1, 2, 3, 4, 5}; int *p = arr; printf("%d", *p++); printf("%d", *(p + 1));
Question




#include<stdio.h>
void main()
{
int arr[] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d", *p++);
printf("%d", *(p + 1));
}
Find the output of the above code?

A.

1, 2

B.

1, 3

C.

2, 3

D.

1, 4

Correct option is B


1. Pointer Operations:
· int *p = arr; initializes p to point to the first element of arr.
· *p++ evaluates *p (value at arr[0], which is 1), then increments p to point to arr[1].
2. Second Print Statement:
· *(p + 1) now refers to arr[2], which has a value of 3.
Information Booster:
· *p++: This increments the pointer after dereferencing.
· Pointer arithmetic is used to move to the next element in memory.

Free Tests

Free
Must Attempt

Basics of Education: Pedagogy, Andragogy, and Hutagogy

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon12 Mins
languageIcon English
Free
Must Attempt

UGC NET Paper 1 Mock Test 1

languageIcon English
  • pdpQsnIcon50 Questions
  • pdpsheetsIcon100 Marks
  • timerIcon60 Mins
languageIcon English
Free
Must Attempt

Basics of Education: Pedagogy, Andragogy, and Hutagogy

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon12 Mins
languageIcon English

Similar Questions

test-prime-package

Access ‘UGC NET Computer Science’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
354k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow