Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 8:44 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 10 posts ] 
Author Question
 Question subject: what is the output of this program and how it be?
PostPosted: Wed Feb 16, 2011 8:01 am 
Offline
Beginner
User avatar

Joined: Sun Jan 09, 2011 2:16 pm
Posts: 56
Has thanked: 1 time
Have thanks: 0 time

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();

_________________
technoyouth


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Fri Feb 18, 2011 2:58 pm 
Offline
Beginner
User avatar

Joined: Sun Jan 09, 2011 2:16 pm
Posts: 56
Has thanked: 1 time
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

_________________
technoyouth


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Fri Feb 18, 2011 3:37 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2272
Location: Earth
Has thanked: 39 time
Have thanks: 61 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

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Fri Feb 18, 2011 4:29 pm 
Offline
Beginner
User avatar

Joined: Sun Jan 09, 2011 2:16 pm
Posts: 56
Has thanked: 1 time
Have thanks: 0 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...

_________________
technoyouth


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Sun Feb 20, 2011 10:21 am 
Offline
Newbie
User avatar

Joined: Sun Feb 20, 2011 10:11 am
Posts: 1
Has thanked: 0 time
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])


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Tue Feb 22, 2011 5:13 pm 
Offline
Newbie
User avatar

Joined: Mon Feb 21, 2011 9:11 am
Posts: 2
Has thanked: 0 time
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"


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Sat Feb 26, 2011 2:31 pm 
Offline
Beginner
User avatar

Joined: Sun Jan 09, 2011 2:16 pm
Posts: 56
Has thanked: 1 time
Have thanks: 0 time
thanku bro...i think it is ascii value not decimal value...

_________________
technoyouth


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Sun Feb 27, 2011 7:13 am 
Offline
Beginner
User avatar

Joined: Sun Jan 09, 2011 2:16 pm
Posts: 56
Has thanked: 1 time
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]...??

_________________
technoyouth


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Thu Mar 03, 2011 6:48 am 
Offline
Newbie
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 1
Has thanked: 0 time
Have thanks: 0 time
its 2011 as per my knowledge
.....


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: what is the output of this program and how it be?
PostPosted: Wed Mar 09, 2011 5:39 am 
Offline
Newbie
User avatar

Joined: Mon Mar 07, 2011 6:47 am
Posts: 3
Has thanked: 0 time
Have thanks: 0 time
Highly informative post, thanks u for sharing!!..


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 10 posts ] 
Quick reply


  

 Similar topics
 I need you to help me to solve this program by c++ language
 How to write a JSP Program to manipulate Last Date visited
 C C++ program help using class
 how to write a "c' program on fibannoic series
 Java Program for communicate PC and Mobile
 java chat program written by Mr.muhammed.
 HOW TO DO C++ PROGRAM?
 c++ program
 run .exe program in matlab
 Need help with code for a while loop program

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team