Thread: Changing the value of an varibale in an if statement?

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    4

    Changing the value of an varibale in an if statement?

    Being the c newbie that I'm I have a question about changing the value of an variable in an if statement. Since I only have experience from matlab where this works like a charm I wonder if it's the same for C. I'll give an example if you don't understand what i mean.

    Code:
    int w = 1;
    int b = 2;
    int c = 3;
    
    if(w==1){
         b=b+1;
    }
    
    int a = b+c;
    This will give a=6 right? I don't need to use pointers to change the value with an if statment?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    74
    yep, seems that way.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    269
    Certainly, that would work.. are u getting an error?

  4. #4
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    Might get an error for not declaring a at the start of the block though?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. if else statement ????
    By pczafer in forum C++ Programming
    Replies: 11
    Last Post: 04-29-2009, 08:45 AM
  2. Switch statement / default:
    By kcpilot in forum C Programming
    Replies: 4
    Last Post: 12-02-2008, 03:14 PM
  3. Using while loop for if statement.
    By Galens in forum C++ Programming
    Replies: 5
    Last Post: 10-03-2008, 03:14 PM
  4. having trouble understanding this statement
    By kes103 in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2003, 09:00 AM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM