CPP
#include<iostream> using namespace std; int main() { const char *s = "" ; char str[] = "Hello" ; s = str; while (*s) printf ( "%c" , *s++); return 0; } |
选项 a) 错误 b) H c) 你好 d) Hel
ans:- c
说明:
const char *s = "";
常量变量s被声明为指向字符类型数组的指针,并用空字符串初始化。
char str[] = "Hello";
变量str被声明为字符类型的数组,并用字符串“Hello”初始化。
s = str;
变量str的值被分配给变量s。因此str包含文本“Hello”。
while(*s){ printf("%c", *s++); }
这里执行while循环,直到变量s的值可用,并打印变量s的每个字符。 因此,程序的输出是“Hello”。 问题2.该项目的产出是什么?
CPP
#include<iostream> using namespace std; int get(); int main() { const int x = get(); printf ( "%d" , x); return 0; } int get() { return 20; } |
选项 a) 垃圾值 b) 错误 c) 二十 d) 0
ans:- c
说明:
int get();
这是函数get()的函数原型,它告诉编译器返回一个整数值,不接受任何参数。
const int x = get();
常量变量x被声明为整数数据类型,并用值“20”初始化。 函数get()返回值“20”。 问题3.该项目的产出是什么?
CPP
#include<iostream> using namespace std; int fun( int **ptr); int main() { int i=10; const int *ptr = &i; fun(&ptr); return 0; } int fun( int **ptr) { int j = 223; int *temp = &j; printf ( "Before changing ptr = %5x" , *ptr); const *ptr = temp; printf ( "After changing ptr = %5x" , *ptr); return 0; } |
选项 a) 我的地址 j.的地址 b) 十 223 c) 错误:无法将参数1从“常量int**”转换为“int**” d) 垃圾值
ans:- c
说明: 这里,ptr被声明为常量整数指针,i的地址被分配到该指针,但在函数fun中,双指针作为参数传递,因此它不能从“const int**”转换为“int**”。 问题4.该项目的产出是什么?
CPP
#include<iostream> using namespace std; int main() { const int i=0; printf ( "%d" , i++); return 0; } |
选项 a) 十 b) 11 c) 没有输出 d) 错误:++需要一个值
ans:- d
说明:
const int i = 0;
常量变量“i”被声明为整数,并用值“0”(零)初始化。
printf("%d", i++);
这里变量“i”增加1(一)。这将创建一个错误“无法修改常量对象”。 因为,我们不能修改常量变量。 问题5.该项目的产出是什么?
CPP
#include<iostream> using namespace std; int main() { const int c = -11; const int d = 34; printf ( "%d, %d" , c, d); return 0; } |
选项 a) 错误 b) -11,34 c) 11,34 d) 这些都不是
ans:- b
说明:-
const c = -11;
常量变量“c”被声明并初始化为值“-11”。
const int d = 34;
常量变量“d”被声明为整数,并初始化为值“34”。
printf("%d, %d", c, d);
将打印变量“c”和“d”的值。 因此程序的输出是-11,34 本文由 布拉格亚·辛格 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。 如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。