Saturday, December 5, 2015

main() function and return datatype in c

Description:
Why we need to keep void always to main().
Shall we try assign different type of datatypes?

Program #8
/* Usual way of void as return to main() */
# include "stdio.h"
void main(){
  clrscr();
  printf("void main() function in c (no more return) !!");
  getch();
 
  //no return
}

Output:
void main() function in c (no more return) !!

Program #9
/* int as return datatype to main() */
# include "stdio.h"
int main(){
  clrscr();
  printf("main() function in c (return integer) !!");
  getch();
 
  //return integer value, any as you wish
  return 1306;
}

Output:
main() function in c (return integer) !!

Program #10
/* float as return datatype to main() */
# include "stdio.h"
float main(){
  clrscr();
  printf("main() function in c (return float) !!");
  getch();
 
  //return float value, any as you wish
  return 13.06;
}

Output:
main() function in c (return float) !!

Program #11
/* char as return datatype to main() */
# include "stdio.h"
char main(){
  clrscr();
  printf("main() function in c (return char) !!");
  getch();
 
  //return char value, any as you wish
  return 'm';
}

Output:
main() function in c (return char) !!

Program #12
/* double as return datatype to main() */
# include "stdio.h"
double main(){
  clrscr();
  printf("main() function in c (return double) !!");
  getch();
 
  //return double value, any as you wish
  return 130600;
}







Output:
main() function in c (return double) !!

No comments:

Post a Comment

Popular Posts