the output of this parameter is 67. How?

0 votes
asked May 3 by Venkat (160 points)
#include <stdio.h>
int a = 12, b = 56, c = 73, d = 33;             /*Declaration of global variables which can used in any function within this programme*/
int add(int);                   /*declaration of user defined function*/
int main()
{
    int n;
    n= add(150);
    printf("The global variables defined in this programme can be accessed here %d %d %d %d\n", a, b, c, d);
    printf("The local variable declared within add function can be accessed here %d \n",n);
}
int add(int zxy)
{
    printf("The local variable declared within add function can be accessed here %d \n", zxy);
    printf("The global variable declared can be accessed here also %d %d %d %d\n", a, b, c, d);
}

2 Answers

0 votes
answered May 18 by NickCutin (140 points)
The add function need to have a return value, if no return is assigned then it takes some value inside the function itself that depend of which algorith you use (for example you can try removing the second "printf", and you'll find another value to "n")

Hope to have answered you question.
0 votes
answered May 24 by rgajjar (180 points)
The reason is that you have not assigned a return value to your function "int add(zxy)".

Please add the following return statement in your function implementation:-

int add(int zxy)
{
    printf("The local variable declared within add function can be accessed here %d \n", zxy);
    printf("The global variable declared can be accessed here also %d %d %d %d\n", a, b, c, d);
    
    return zxy;  /*!<return statement is added.>*/
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...