By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

C/C++ _Pointers and array

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

static int retval = 0;
*val = retval++; -----> what result ?
}
Mar 31 '17 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 2,396
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...
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. void Saras015(int *val);
  4.  
  5. int main(void) {
  6.   int mainVal;
  7.  
  8.   mainVal = 100;
  9.   printf("%d\n", mainVal);
  10.  
  11.   Saras015(&mainVal);
  12.   printf("%d\n", mainVal);
  13.  
  14.   Saras015(&mainVal);
  15.   printf("%d\n", mainVal);
  16.  
  17.   return 0;
  18. }
  19.  
  20.  
  21. void Saras015(int *val) {
  22.    Same as you had before
  23. }
Run this and see what hints it gives you regarding what Saras015 is doing.
Mar 31 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.