C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28691
Number of posts: 94711

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
This code produces Posted by Panasonic99 on 8 Aug 2005 at 3:32 PM
include <stdio.h>

void xxx( int*, int);
void main()
{
int x =4, y = 13;
xxx(&x, y);
printf("%d%d\n", x, y);
}

void xxx(int* x, int y)
{
*x += 4;
y += 7;
printf("%d%d\n", *x, y);
}


820
813

I cant understand why-
Report
Re: This code produces Posted by stober on 8 Aug 2005 at 4:48 PM
This message was edited by stober at 2005-8-8 16:48:40

: include <stdio.h>
:
: void xxx( int*, int);
: void main()
: {
: int x =4, y = 13;
: xxx(&x, y);
: printf("%d%d\n", x, y);
: }
:
: void xxx(int* x, int y)
: {
: *x += 4;
: y += 7;
: printf("%d%d\n", *x, y);
: }
:
:
: 820
: 813
:
: I cant understand why-
:

you need to separate the numbers with one or more spaces -- they are all run togethere.
:   printf("%d  %d\n", *x, y);



Report
Re: This code produces Posted by pseudocoder on 8 Aug 2005 at 4:51 PM
Look at your format specifiers in the printf statements

%d%d will make two numbers appear as one, or if you don't know where the 8 came from, then read up on pointers a bit more.

: include <stdio.h>
:
: void xxx( int*, int);
: void main()
: {
: int x =4, y = 13;
: xxx(&x, y);
: printf("%d%d\n", x, y);
: }
:
: void xxx(int* x, int y)
: {
: *x += 4;
: y += 7;
: printf("%d%d\n", *x, y);
: }
:
:
: 820
: 813
:
: I cant understand why-
:



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.