C/C++ _Pointers and array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Saras015
    New Member
    • Mar 2017
    • 1

    C/C++ _Pointers and array

    void main(int* val)----> Can anyone explain about that Pointer funtion
    {

    static int retval = 0;
    *val = retval++; -----> what result ?
    }
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Function main is special - it is the only (*) C function whose interface (that is, its function prototype) is specified in the C Standard. You can't change it. Your definition here for main is not compatible with the C Standard. You should change the name of your function (I'll call it Saras015). You will still need a legal main function, but I suggest you use it to call Saras015.

    Try this...
    Code:
    #include <stdio.h>
    
    void Saras015(int *val);
    
    int main(void) {
      int mainVal;
    
      mainVal = 100;
      printf("%d\n", mainVal);
    
      Saras015(&mainVal);
      printf("%d\n", mainVal);
    
      Saras015(&mainVal);
      printf("%d\n", mainVal);
    
      return 0;
    }
    
    
    void Saras015(int *val) {
       [I]Same as you had before[/I]
    }
    Run this and see what hints it gives you regarding what Saras015 is doing.
    Last edited by donbock; Mar 31 '17, 01:46 PM. Reason: (*) ok, the C Standard also specifies the interfaces for the Standard Library functions; but you have the option to redefine those interfaces and write your own library functions. Bad idea!

    Comment

    Working...