Thread: function variables

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    function variables

    is it possible to declare a function variable further down in the code?

    and does it being in a struct have anything to do with how it acts?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What do you mean by 'function variable'?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    As far as I know, the phrase "function variable" means a variable used in the function, so that is how I will answer your question. You can pass into functions any variable you want, but that variable you pass in must also be declared before the function is called. You must declare and initialize a local variable in the function before you try to access it.

    A variable in a struct is just like any other most (all?) of the time, the only real difference is that its been tossed into a bucket.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    function variable you know ill link to a apge i use
    http://www.zeuscmd.com/tutorials/cpl...-Functions.php

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    It does not mention "function variable" anywhere. Can you elaborate?
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Correct.

    no members variables inside struct

    yes anywhere local variables

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM