Total members 11890 |It is currently Fri Apr 19, 2024 8:07 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Hi friendzz..Can any body tell me the output of this program and explain how it came....and also how these operations (p+p[3]-p[1] ) performed


Code:
#include<stdio.h>
#include<conio.h>
void main()
{
char  c[]="GATE2011";
char *p=c;
clrscr();
printf("%s",p+p[3]-p[1]);
getch();





Author:
Beginner
User avatar Posts: 54
Have thanks: 0 time

Is there Any body to explain this.....k ivl give the output, plz i need explanation how this output came?

output is : 2011


Author:
Beginner
User avatar Posts: 54
Have thanks: 0 time

%s used to print a string of characters .

i didn't run this app, but it seems this p[3]-p[1] part removed the First part of the string . are you sure that the output is 2010 or G2011

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

sure it's 2011 (check once if possible)...
but i need hw this output came i.e. what operations takes place here on p...whether it performs on p's address or ascii values of "p" or any other...


Author:
Beginner
User avatar Posts: 54
Have thanks: 0 time

This code is equivalent to
Code:
p + (69 - 65)


where 69 is the decimal equivalent of 'E' (p[3]) and 65 is the decimal equivalent of 'A' (p[1])


Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

Statement will be: (as written above)
p+(69-65)

For example, if the code is as follows:
printf("%s",p+1);

output will be "ATE2011"

Similarly for
printf("%s",p+2);

output will be "TE 2011"

ASCII values of A(p[1]) and E(p[3]) are 69 and 65 respectively, so it will be "p+(69-65)" and the output will be "2011"


Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

thanku bro...i think it is ascii value not decimal value...


Author:
Beginner
User avatar Posts: 54
Have thanks: 0 time

pyromaniac wrote:
Statement will be: (as written above)
p+(69-65)

For example, if the code is as follows:
printf("%s",p+1);

output will be "ATE2011"

Similarly for
printf("%s",p+2);

output will be "TE 2011"

ASCII values of A(p[1]) and E(p[3]) are 69 and 65 respectively, so it will be "p+(69-65)" and the output will be "2011"


thank u dude...but p contains the address of the string....but how it can store ascii value in p[1] and p[3]...??


Author:
Beginner
User avatar Posts: 54
Have thanks: 0 time

its 2011 as per my knowledge
.....


Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

Highly informative post, thanks u for sharing!!..


Author:
Newbie
User avatar Posts: 3
Have thanks: 0 time
Post new topic Reply to topic  [ 10 posts ] 

  Related Posts  to : what is the output of this program and how it be?
 OUTPUT??     -  
 Input-Output Operations     -  
 echo command to output HTML     -  
 output associate array by print_r     -  
 Use for loop to output HTML table     -  
 HOW TO DO C++ PROGRAM?     -  
 java program     -  
 java program     -  
 how can i DeployPHP Program     -  
 write a program in c++ for the following...     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com