Program Ape's---C language details 27 (function without parameter details, function default return int type proof, return default return value, void pointer + + operation)

Source: Internet
Author: User

Main content: function without parameter details, function default return int type proof, return default return value, void pointer + + operation

First, the function without parameters when the details

The function should be void when there are no arguments

A function in the C language

void f ();

Pass parameter F (2) when used, no error, and error in C + +

It is best to add void to clarify that the function is parameterless

Second, the function default return type is int type

See procedure below

Return default returns 1

Detail: Return cannot return a pointer in the execution stack memory because the memory is automatically destroyed at the end of the function body

D. void pointer + + operation

void *p;

p++; Error in ANSI compilation, p++ and char* consistent in GNU compiler

#include <stdio.h> A () {return 3;//return;//directly written in this form the default is to return 1}b (int a, int b) {return a+b;} int main () {printf ("func A return =%d\n", A (2));   function no parameter should be declared void, in C does not declare the parameter is not error, in C + + will be error, so regardless of C + +, function without parameters declared void printf ("func b retunr =%d\n", b (300,5000)); This shows that the function has no return type and returns the int type printf ("-------------------------\ n") by default; void *p;         p++;//uses the compiler GCC, mingw5 compilation pass (i.e. GNU), which they consider p++ as char* type, using VC6.0 compile error (i.e. ANSI) return 0;}
Output:



Program Ape's---C language details 27 (function without parameter details, function default return int type proof, return default return value, void pointer + + operation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.