Sponsored Content
Top Forums Programming Question on integer variables (c++) Post 302513672 by Corona688 on Wednesday 13th of April 2011 08:42:29 PM
Old 04-13-2011
Quote:
Originally Posted by orszhak
Hello guys! It's orszhak and in my book I am currently studying incrementing values in c++ and it states thant I could do this to increment the value of nVariable
Code:
 nVariable = nVariable + 2;

it states that I could also do this and assign the same value
Code:
 nVariable += 2;

but can't I also do this and assign the same value to the variable? here:
Code:
 nVariable = 2;

Or what about this
Code:
 int variable;
variable = 2;

Anyways thanks guys! Smilie
I'm guessing you're confused on the concept of increment. += 2 adds two, it doesn't set it to two.

Code:
#include <stdio.h>

int main(void)
{
        int variable;
        variable=0;

        printf("variable is %d\n", variable);

        variable += 2;
        printf("variable is %d\n", variable);
        variable = variable + 2;
        printf("variable is %d\n", variable);
        variable=2;
        printf("variable is %d\n", variable);
        return(0);
}

If that's not what you mean, I'm sorry, I don't understand your question.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question variables Korn

I'm using the following command to test for certain characters in a script echo "${1}" | grep '\$' if (( ${?} == 0 )) then testing this script on the command line I have ksh -x script1.sh "xxxx$xxxx" this works fine but when I want to use ksh -x script1.sh "xxxx $xxx" the... (1 Reply)
Discussion started by: frank
1 Replies

2. UNIX for Dummies Questions & Answers

Question about variables

I am looking for 8 variables in the following profile. I am looking to see if anyone could explain this for me better than the book I am using has been able to. There are 5 system, 2 aliases, and one editor. The profile is as follows: # @(#)local.profile 1.8 99/03/26 SMI stty istrip... (0 Replies)
Discussion started by: wswaner
0 Replies

3. Shell Programming and Scripting

question about variables with sed

Hi, I am trying to do some mass replacements in lots of scripts, and using sed. However sed doesn't seem to like to be able to dereference variables within the substitute clause. For example: tab=newtable cat f1 | sed 's/oldtable/$tab/g' doesn't work. it would replace oldtable with the... (2 Replies)
Discussion started by: fwellers
2 Replies

4. Shell Programming and Scripting

Question about variables

What does this mean? #!/bin/bash BACKUPFILE=backup-$(date +%m-%d-%Y) archive=${1:-$BACKUPFILE} (4 Replies)
Discussion started by: hin-linux
4 Replies

5. Linux

Question about Variables in If?

Hi everybody, im trying to store a path "address" of a file in a variable, then IF the Address that the user entered INSIDE the variable is exist, do something, else echo invalid file address. here's my code, but it's not working i dunno why: $variable cat > variable #variable will contain... (4 Replies)
Discussion started by: iam_ako
4 Replies

6. UNIX for Dummies Questions & Answers

Variables question

Hi I am trying to find were to look for definitions of these variables; $0, $1, $2, $#, $$ , $*. I am not having much luck with my searching. Can anyone point me in the right direction? Thanks, Doug (3 Replies)
Discussion started by: Reddoug
3 Replies

7. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

8. Shell Programming and Scripting

Handling null Integer/string variables

I kind of found out the hard way that I am not able to manipulate the null value, the long silence that happens when there is no value returned. I am looking for PIDs, and when there is no PID return, I wanted to handle this special scenario. Here is my script. #!/bin/bash LAN_VARIABLE=... (7 Replies)
Discussion started by: lan123
7 Replies

9. Shell Programming and Scripting

How to compare floating variables , integer value expected?

I am running some commands and I am trying to get an output into a variable. I am having problem when I try to put that value in while loop, it says integer value expected. What's the best way to accomplish this remaining=$(symclone -sid XXX -f Clone_test query | grep MB | awk '{print... (1 Reply)
Discussion started by: rajsan
1 Replies

10. UNIX for Dummies Questions & Answers

Question On Sourcing Variables

I have 2 scripts first script would call second script. test1.sh #!/bin/bash logfile=`basename $0`.log echo "First File" >> $logfile TIME=`ls -lu array.ksh | awk '{print $6" "$7" "$8}'` . /home/infrmtca/bin/Test/test2.sh #/home/infrmtca/bin/Test/test2.sh test2.sh #!/bin/bash... (1 Reply)
Discussion started by: Ariean
1 Replies
scope(n)							    [incr Tcl]								  scope(n)

NAME
scope - capture the namespace context for a variable SYNOPSIS
scope name DESCRIPTION
Creates a scoped value for the specified name, which must be a variable name. If the name is an instance variable, then the scope command returns a string of the following form: @itcl object varName This is recognized in any context as an instance variable belonging to object. So with itcl3.0 and beyond, it is possible to use instance variables in conjunction with widgets. For example, if you have an object with a private variable x, and you can use x in conjunction with the -textvariable option of an entry widget. Before itcl3.0, only common vari- ables could be used in this manner. If the name is not an instance variable, then it must be a common variable or a global variable. In that case, the scope command returns the fully qualified name of the variable, e.g., ::foo::bar::x. If the name is not recognized as a variable, the scope command returns an error. Ordinary variable names refer to variables in the global namespace. A scoped value captures a variable name together with its namespace context in a way that allows it to be referenced properly later. It is needed, for example, to wrap up variable names when a Tk widget is used within a namespace: namespace foo { private variable mode 1 radiobutton .rb1 -text "Mode #1" -variable [scope mode] -value 1 pack .rb1 radiobutton .rb2 -text "Mode #2" -variable [scope mode] -value 2 pack .rb2 } Radiobuttons .rb1 and .rb2 interact via the variable "mode" contained in the namespace "foo". The scope command guarantees this by returning the fully qualified variable name ::foo::mode. You should never use the @itcl syntax directly. For example, it is a bad idea to write code like this: set {@itcl ::fred x} 3 puts "value = ${@itcl ::fred x}" Instead, you should always use the scope command to generate the variable name dynamically. Then, you can pass that name to a widget or to any other bit of code in your program. KEYWORDS
code, namespace, variable itcl scope(n)
All times are GMT -4. The time now is 08:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy