📄 reftst2.cpp
字号:
/*
reftst2.cpp. Testing the reference operator
*/
#include <stdio.h>
#include <string.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 FuncOne(int x, TESTER &t, int y);
int main()
{
int a = 2, b = 3;
TESTER test = {1, 'X', "This is a string"};
FuncOne (a, &test, b); // Using pointer
printf ("\ttest.x = %d\n", test.x);
printf ("\ttest.ch = %c\n", test.ch);
printf ("\ttest.str = %s\n", test.str);
FuncOne (a, test, b); // Using reference
printf ("\ttest.x = %d\n", test.x);
printf ("\ttest.ch = %c\n", test.ch);
printf ("\ttest.str = %s\n", test.str);
return (0);
}
void FuncOne(int x, TESTER *t, int y)
{
printf ("Using normal variable call:\n");
t->x = sizeof (TESTER);
t->ch = 'B';
strcpy (t->str, "Modified String");
}
void FuncOne(int x, TESTER &t, int y)
{
printf ("Using reference variable call:\n");
t.x = 2 * sizeof (TESTER);
t.ch = 'C';
strcpy (t.str, "Changed again, eh?");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -