The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+2 votes
120 views

What is the output of this program?

#include <stdio.h>
int main()
{
	char *ptr;
	char string[] = "Hello 2017";
	ptr = string;
	ptr += 4;
	printf("%s",++ptr);
} 
  1. Hello 2017
  2. ello 2017
  3.  2017
  4. o 2017
asked in Programming by Veteran (362k points) | 120 views

2 Answers

+2 votes
Best answer
ptr += 4; // leave 4 element
printf("%s",++ptr); //increment pointer.

i.e. leave 5 element and after that print untill null is encountered.
 2017
answered by Veteran (55.6k points)
selected by
0 votes
initialy ptr point to H

string will be start printing after 5 character from H

so o/p is 2017
answered by (111 points)
Answer:

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

42,515 questions
48,528 answers
155,018 comments
63,372 users