[000] C language K & R style Definition

Source: Internet
Author: User

A colleague occasionally sent out an interesting piece of code a few days ago, which has never been seen before. It is a collection. It can be defined in C as follows:
Code:

 

#include<stdio.h>void  function(arg1, arg2)int arg1;int arg2;{    printf("arg1=%d,  arg2=%d", arg1, arg2);}int main(){    function(1,2);    function(1);    function();    return 0;}

---------------------------------------------------------------

Output:

    arg1=1, arg2=2
    arg1=1, arg2=2
    arg1=1, arg2=2
------------------------------------
You can also try to change the function call sequence as follows:
    function();
    function(1);
    function(1,2); 
The output is as follows:
    arg1=134513424, arg2=134513755
    arg1=1, arg2=134513755
Arg1 = 1, arg2 = 2

The reason is not the memory function of the function, but the function is called,
The content on the stack (or General registers) is not changed,
Therefore, the output is the same. Whether the output structure is the same each time,
It is based on the compiler and hardware.


If between the call of function (1) and function,
By calling other functions, you can change the stack or register content,
After this call, the source results will be different.

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.