⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reftst.cpp

📁 这些源代码
💻 CPP
字号:
/*
    reftst.cpp. Testing the reference operator
 */
#include    <stdio.h>

// Define the structure
struct TESTER
{
    int     x;
    char    ch;
    char    str[27];
};
// Declare our functions
void FuncOne(int x, TESTER t, int y);
void FuncTwo(int x, TESTER &t, int y);

int main()
{
int a = 2, b = 3;
TESTER test = {1, 'X', "This is a string"};

    printf ("sizeof (TESTER) = %d\n", sizeof (TESTER));
    FuncOne (a, test, b);     // Using variable
    printf ("test.x = %d\n", test.x);
    FuncTwo (a, test, b);     // Using reference
    printf ("test.x = %d\n", test.x);
    return (0);
}

void FuncOne(int x, TESTER t, int y)
{
    printf ("Using normal variable call:\n");
    printf ("\tAddress of x = %ld\n", &x);
    printf ("\tAddress of y = %ld\n", &y);
    printf ("\tDifference is %d\n", (int) &y - (int)(&x+1));
    t.x = sizeof (TESTER);
}

void FuncTwo(int x, TESTER &t, int y)
{
    printf ("Using reference variable call:\n");
    printf ("\tAddress of x = %ld\n", &x);
    printf ("\tAddress of y = %ld\n", &y);
    printf ("\tDifference is %d\n", (int) &y - (int)(&x+1));
    t.x = sizeof (TESTER);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -