473,385 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Another newbie question

Hello yes I am a beginner at writing C++ and have been using Visual Studio C++ 2008, my problem is that when I enter this very simple code

#include <stdio.h>

int main( void )
{
int counter = 1;

do {
printf( "%d " , &counter );
} while ( ++counter <= 10 );

return 0;

}

this code is supposed to simply count from 1 to 10 but instead the results are this

1245024 1245024 1245024 1245024 1245024 1245024 1245024 1245024 1245024 1245024
Press any key to continue...

I have checked the code in the book to the code I wrote numerous times and cannot find anything different except the results they display in the book actually work

Any help would be appreciated,
Nov 5 '08 #1
5 1394
manontheedge
175 100+
where you have "&counter", make it "counter"

what's printing out is the MEMORY ADDRESS of counter, that's the 124... whatever number you're getting. When you put "&" before a variable like you have, you are getting the ADDRESS of it, NOT the value. It's quite possible it's a typo in your book ... I've seen good books with code filled with typos.


...and by the way, your code there is C not C++.
Nov 5 '08 #2
JosAH
11,448 Expert 8TB
Hello yes I am a beginner at writing C++
Please don't hijack somebody else's thread; it is considered rude. I've split your
thread (and reply) to its own thread.

kind regards,

Jos (moderator)
Nov 5 '08 #3
donbock
2,426 Expert 2GB
You may also what some separator between each printed value, maybe a space or a newline.
Nov 5 '08 #4
boxfish
469 Expert 256MB
There is a separator; a space after the %d.
Nov 5 '08 #5
itsraghz
127 100+
The perfect answer was given by "manontheedge" !! Remove the "&" and rerun the program. It will be fine!
Nov 7 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Peter | last post by:
Hello, Two newbie questions: 1) I have a javascript file with a function in it. From this function I want to access a variable in another javascript file -which is not inside a function. I...
4
by: Christian | last post by:
From a not even newbie: Without knowing much about Python (yet) I'm trying to install the CMS Zope via FTP (with the well documented changes to make it work on an Apache server). By birth Zope...
10
by: Saber | last post by:
I did a web search and found someone is looking for what I'm looking for: There are 2 forms...named => formA and formB and each of them have their own button named => btnA and ...
45
by: n.estner | last post by:
Having read previous discussions on python-dev I think I'm not the only Python programmer who doesn't particularly like python's "self" parameter: class Foo: def bar(self, a,b): return a+b...
1
by: Moss | last post by:
Hi, Sorry if this really is a newbie question, but hey, I'm a newbie, porting from a coldfusion background. I have been using the built in login feature however notice that it does appear to...
4
by: RipperT | last post by:
College newbie here (Instructor MIA). I have instructions to pass variable values from one web page to another like this (VS2005): 1. Declare and create the properties on the first page (source...
2
pdring
by: pdring | last post by:
Hi guys, sorry but yet another newbie struggling with the basics! I have a small program that i am working on in wich 1 want to enter exam scores for each of 5 students in turn untill i enter a set...
3
by: HaVeN | last post by:
Hello, I'm not to sure if this was the right place to post this question... I am a newbie to the Community. Anyways, I've built 2 Websites that are all in one solution and I am using VB 2005.At...
5
by: Banibrata Dutta | last post by:
Hi, I've gone through the list of "language differences" between 2.3 / 2.4 & 2.5 of CPython. I've spend around 2 weeks now, learning v2.5 of CPython, and I consider myself still very very...
12
by: jayjayplane | last post by:
Thanks everybody here answered my last data field validation question about the alert of future date. Here I get another question, sorry, I am really an Access newbie... The question is : I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.