aliensbrain
  • Home
  • Study
  • Quizzes
  • 🎤AI Practicefree
  • Notebooks
  • Community
  • Sign in
  • C Programming Fundamentals
  • Determine Output: int main() { int a[5] = {1,2,3,4,5}; in...
Multiple choice technology programming languages

Determine Output: int main() { int a[5] = {1,2,3,4,5}; int ptr = (int)(&a+1); printf("%d %d" , *(a+1), *(ptr-1) ); return 0; }

  1. 2,1

  2. 2,5

  3. compile error

  4. 2,2

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

*(a+1) accesses the second element (index 1) = 2. (&a+1) points past the entire array, so ptr-1 points to the last element = 5. Output is '2 5'.

Keep practicing — related questions

  • int y[4] = {6, 7, 8, 9}; int *ptr = y + 2; printf(%dn, ptr[ 1 ] ); /*ptr+1 == ptr[1]*/ What is printed, whe...
  • What will be the output of the following program? void main() { int val=1234; int* ptr=&val; printf("%d %d"...
  • void main() { int *ptr; int item=5; int arr[]={10,20,30,40,50}; ptr = &item; for(;item>=0;item--) { printf(...
  • What will be the output of the following program : void main() { int val=5; void *ptr; *(int *)ptr=5; val=p...
  • Find the output of this program. main() { int a[10]; printf("%d",*a+1-*a+3) ; }
  • Find the output of this program. main() { int a[10]; printf("%d",*a+1-*a+3) ; }
  • What will be the output of the following program : void main() { int val=50; void *ptr; ptr=&val; printf("%...
  • #include main() { int a[2][2][2] = {{10,2,3,4},{5,6,7,8}}; int *p,*q; p=&a[2][2][2]; *q=***a printf("%d----...
Play the full quiz 🎤 Practise this topic out loud
Advertisement
© Aliensbrain | all rights reserved
  • About
  • Contact
  • Terms and Condition
  • Privacy Policy