Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

void keyword

Question posted by: filitsa (Newbie) on March 13th, 2007 01:16 PM
Hello to all,
I am a trying really hard to understand keywords for a rerort I have to make for my university but I don't seem to get the main idea....
There is a question and if you have any ideas there are all very very wellcome:
Whitch yould be the outcome after operating the func3 ( ), Explain ???
Expand|Select|Wrap|Line Numbers
  1. void func1 (int a)
  2. {
  3.               a=10;
  4. }
  5. int func2 (int a)
  6. {
  7.               a=10;
  8.               return (a);
  9. }
  10. void func3 ( )
  11. {
  12.               int a=2;
  13.               int b=5;
  14.  
  15.               func1 (a);
  16.               b=func2 (a);
  17.               printf("a=%d,  b=%d\n", a, b);
  18. }


Best Regards from Greece
Filitsa
sicarie's Avatar
sicarie
Moderator
3,795 Posts
March 13th, 2007
01:57 PM
#2

Re: void keyword
Quote:
Hello to all,
I am a trying really hard to understand keywords for a rerort I have to make for my university but I don't seem to get the main idea....
There is a question and if you have any ideas there are all very very wellcome:
Whitch yould be the outcome after operating the func3 ( ), Explain ???
Expand|Select|Wrap|Line Numbers
  1. void func1 (int a)
  2. {
  3.               a=10;
  4. }
  5. int func2 (int a)
  6. {
  7.               a=10;
  8.               return (a);
  9. }
  10. void func3 ( )
  11. {
  12.               int a=2;
  13.               int b=5;
  14.  
  15.               func1 (a);
  16.               b=func2 (a);
  17.               printf("a=%d,  b=%d\n", a, b);
  18. }


Best Regards from Greece
Filitsa


Ok, so this is a pretty basic example - what were you thinking about this one? Did you try to trace through it with a value? (Hint, assign arbitrarily small values to a and b and move through each line yourself)

Reply
Ganon11's Avatar
Ganon11
Moderator
3,309 Posts
March 13th, 2007
02:37 PM
#3

Re: void keyword
There's no point in assigning arbitrary values to a and b - they are given values in the first two lines of func3. Knowing what you know about scope and functions, step through the program and find out what answers will be.

Reply
sicarie's Avatar
sicarie
Moderator
3,795 Posts
March 13th, 2007
02:43 PM
#4

Re: void keyword
Quote:
There's no point in assigning arbitrary values to a and b - they are given values in the first two lines of func3. Knowing what you know about scope and functions, step through the program and find out what answers will be.

Haha, ah, I feel like an idiot... :(

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,088 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top C / C++ Forum Contributors