Sponsored Content
Full Discussion: what is the exact reason ?
Top Forums Programming what is the exact reason ? Post 11601 by parmenides on Saturday 8th of December 2001 12:05:09 PM
Old 12-08-2001
The effect of the '++' (and all of this applies to '--' as well) operator changes depending on where you put it. If your put it before the variable you're modifying, then the program will increment the variable before using the variable in any sort of statement, thus

a = ++b;

means

b = b + 1;
a = b;

However, if the operator comes after the variable, then the increment is executed after any expressions the variable is in.

b = a++;

means

b = a;
a = a + 1;


The first statement performs all the adding before all the incrementing, so i remains at 1 until after the value is assigned to j.

j = i + i; // j is 2
i = i + 1; // i is now 2
i = i + 1; // i is now 3

The second statement does all the incrementing first, so it adds one to i twice before adding it two itself, and assigning that value to j.

i = i + 1; // i is now 2
i = i + 1; // i is now 3
j = i + i; // j is now 6 (3+3)

If you switched either of the incrementors in either statement to the other side, then you (ought) to get 4.

P.

Last edited by parmenides; 12-08-2001 at 03:06 PM..
 

7 More Discussions You Might Find Interesting

1. Programming

Reason for Segmentation fault

The following program fails with "Segmentation fault" error message, while I try to run in Ubuntu (Debian) Linux m/c. It is not creating any core file, so I could not cross examine it with the debugger. See the comments for much better understanding. Could any one tell me the exact reason why the... (20 Replies)
Discussion started by: royalibrahim
20 Replies

2. Red Hat

Server usually restart not reason

Hi everyone, - I have CentOs server 5.4 , I usually remote by ssh. - My problem is server usually restart but I don't reason. I check log in file /var/log/messages: I don't see "signal 15" which kernel have to receive before restart. Everyone can see in attach. - I try to restart with command... (3 Replies)
Discussion started by: vietbk87
3 Replies

3. UNIX for Advanced & Expert Users

programs are being autostarted for no reason

I have nothing in these folders and several programs are being autostarted for no reason. Chromium, nautilus, Okular, and quadrapassel are the programs being started. I have nothing in my .bashrc. Not sure where else to look. I have no idea why this is happening and it is driving me crazy. ... (0 Replies)
Discussion started by: cokedude
0 Replies

4. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

5. Shell Programming and Scripting

echo exact xml tag from an exact file

Im stumped on this one. Id like to echo into a .txt file all names for an xml feed in a huge folder. Can that be done?? Id need to echo <name>This name</name> in client.xml files. $path="/mnt/windows/path" echo 'recording names' cd "$path" for names in $path than Im stuck on... (2 Replies)
Discussion started by: graphicsman
2 Replies

6. AIX

Cluster failure reason

Hi guys ! I'm a French IT student in AIX, and i'm note very fluent in english. I have a task : Write a script to inform the administrator if on of a cluster UC is not working. I'm not going to ask you the script ^^' But i want to make a list of the failure reason of a cluster (network,... (10 Replies)
Discussion started by: Tharsan
10 Replies

7. OS X (Apple)

What's the reason behind having -n option for mv command?

Sorry for a question that may seem dumb but learning UNIX basics I still can not grasp benefits of using mv -n source file target file I can understand the need for cp -n source file target file when you get a copy with contents untouched but the former baffles me. I know that this about... (8 Replies)
Discussion started by: scrutinizerix
8 Replies
EXECUTE(7)                                                         SQL Commands                                                         EXECUTE(7)

NAME
EXECUTE - execute a prepared statement SYNOPSIS
EXECUTE name [ ( parameter [, ...] ) ] DESCRIPTION
EXECUTE is used to execute a previously prepared statement. Since prepared statements only exist for the duration of a session, the pre- pared statement must have been created by a PREPARE statement executed earlier in the current session. If the PREPARE statement that created the statement specified some parameters, a compatible set of parameters must be passed to the EXECUTE statement, or else an error is raised. Note that (unlike functions) prepared statements are not overloaded based on the type or number of their parameters; the name of a prepared statement must be unique within a database session. For more information on the creation and usage of prepared statements, see PREPARE [prepare(7)]. PARAMETERS
name The name of the prepared statement to execute. parameter The actual value of a parameter to the prepared statement. This must be an expression yielding a value that is compatible with the data type of this parameter, as was determined when the prepared statement was created. OUTPUTS
The command tag returned by EXECUTE is that of the prepared statement, and not EXECUTE. EXAMPLES
Examples are given in the Examples [prepare(7)] section of the PREPARE [prepare(7)] documentation. COMPATIBILITY
The SQL standard includes an EXECUTE statement, but it is only for use in embedded SQL. This version of the EXECUTE statement also uses a somewhat different syntax. SEE ALSO
DEALLOCATE [deallocate(7)], PREPARE [prepare(7)] SQL - Language Statements 2010-05-14 EXECUTE(7)
All times are GMT -4. The time now is 11:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy