Help Needed in 'C'

Status
Not open for further replies.

desiboy

Active Member
1,544
2008
7
0
My lecturer asked me to solve this problem ...
I was not able to solve this :(
if any one has a solution please post it ( with valid arguments )
PHP:
#include <stdio.h>
#include <stdlib.h>

void foo(void);

int main (void)
{
        int i=2;
        foo();
        printf ("%d\n",i);
        return EXIT_SUCCESS;
}
void foo(void)
{
    // add code so that printf above prints different value of i (other than 2)
}
 
2 comments
i know c++ so dunno how to write with proper syntax in c. What u need to do is pass the variable "i" by REFERENCE and change the value by adding any number in that foo function.

in c++ the code will look like (m just writing the lines which needs to be changed)
in main, pass i in the foo function:
foo(i);

and make foo function line this:
foo(int &z);
{z++;}
 
Status
Not open for further replies.
Back
Top