incrementing variables in C++


 
Thread Tools Search this Thread
Top Forums Programming incrementing variables in C++
# 1  
Old 07-25-2009
incrementing variables in C++

Hello,

what is the result of the below, and how does it work?

Code:
int i = 5;
cout << i++ * ++i << endl;
cout << i << endl;

# 2  
Old 07-25-2009
Compile it and find out. Because this looks like a homework assignment.
# 3  
Old 07-25-2009
No, this is not a homework assignment.
# 4  
Old 07-25-2009
int i = 5;
cout << i++ * ++i << endl;
cout << i << endl;

The integer is 5.

++ is an increment to the integer and then adds 1 to the variable if it precedes the variable. If it follows the value of the variable returns the value before it was incremented.

Most likely the value of that is 30 (5*6) but yeah, learn to compile Smilie
# 5  
Old 07-26-2009
# 6  
Old 07-27-2009
Quote:
Originally Posted by milhan
No, this is not a homework assignment.
If this is not a homework, can we know the intention behind this question?
Are you looking for explanation on how it works? Please clarify
# 7  
Old 07-27-2009
Quote:
Originally Posted by matrixmadhan
If this is not a homework, can we know the intention behind this question?
Are you looking for explanation on how it works? Please clarify
looking for an explanation on how it works.. as my first post states.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difficulty with incrementing Variables and using the results in a If/else statement

Environment: BASH version: GNU bash, version 3.2.51(1)-release (sparc-sun-solaris2.10) Copyright (C) 2007 Free Software Foundation, Inc. OS: Oracle Solaris 10 9/10 s10s_u9wos_14a SPARC Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. ... (4 Replies)
Discussion started by: os2mac
4 Replies

2. Shell Programming and Scripting

Help with incrementing data in some field

Hi I have the below set of lines , i need to duplicate these lines 1000 times, also eevrytime when it is incremented , it should increment the one in Blue color. 130400030000010000200001 130400030000010000200002 140050030000010000200005A eg: 130400030000010000200001... (5 Replies)
Discussion started by: santhoshks
5 Replies

3. UNIX for Dummies Questions & Answers

Help with incrementing the date

I have a date variable like 2012-12-31 ( YYYY -MM -DD ) in flat file and it has to be incremtented by 1 every time i run the script Example : i tried the below script after data modifcation but this does not seem to work expr `20121231 +%Y%m%d` + 1 Note : Mine is not a GNU... (4 Replies)
Discussion started by: akshay01987
4 Replies

4. Shell Programming and Scripting

incrementing the variable name along with the data?

Hello folks. I am trying to increment my variable names to match a counter that is to be used later on... Basically, i have a for loop that lists directories (for example TEST_OS DVP_OS PROD_OS ) but this loop is not static, it may contain 3 directory once and the next run 5 directories. I... (6 Replies)
Discussion started by: Stephan
6 Replies

5. UNIX for Dummies Questions & Answers

Incrementing variable in for

Hi, want to increment a variable in a for loop like this: for (( c=$total-1; c>=0; c-- )) do if ; then maximo=$valores fi done But it gives the error: No such file or directory How can i do this only incrementing the c variable? Thanks (8 Replies)
Discussion started by: limadario
8 Replies

6. Shell Programming and Scripting

Incrementing with a twist - please help

I'm currently trying to write a ksh or csh script that would change the name of a file found in directories and attach to the name an incrementing three digit number. I know how to write a script that will go: 000, 001, 002, 003, etc The twist is I need more increments then allowed by a 3... (11 Replies)
Discussion started by: Rust
11 Replies

7. Shell Programming and Scripting

Incrementing in while loop

echo "Enter Starting id:" echo "" read rvst_strt_idxx echo "" echo "Enter Closing id:" echo "" read rvst_clsn_idxx FIELD1=$rvst_strt_idxx FIELD2="USER" FIELD3="TEST" FIELD4="12345" FIELD5="00000" echo "" echo "INSERT INTO TABLE( FIELD1, FIELD2, FIELD3, FIELD4, ... (7 Replies)
Discussion started by: ultimatix
7 Replies

8. Post Here to Contact Site Administrators and Moderators

No. post not incrementing

Hi Admin, i just noticed that when I do postings, the number does not increment. eg : Post A -Total Posts 312 Post B - Total Posts 312 Post C - Total Posts 313 Post D - Total Posts 313 Why is this so? Can you kindly check this out? Thank you. (5 Replies)
Discussion started by: incredible
5 Replies

9. Shell Programming and Scripting

shell script help: sorting, incrementing environment variables and stuff

First: me == noob. Whats a good resource for shell script info cause I'm having trouble finding good info. I'm writing a shell script to automate the setup of a flash 'page flip'. My current code is below. the page flip takes an xml file of format <content> <pages... (1 Reply)
Discussion started by: secoif
1 Replies

10. Shell Programming and Scripting

incrementing a for loop

I have, LIST="a b c d e" for word in $LIST do echo $word done would give me a b c d e With the first iteration of the for loop, I get "a" as the result. Is it possible that I get both "a" and "b" in only the first iteration. In the next iteration I get "c" and "d" and so on.... (2 Replies)
Discussion started by: run_time_error
2 Replies
Login or Register to Ask a Question