c-style字符字符串

C programming String Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Strings, String is the set of characters and String related Aptitude Questions and Answers you will find here.

C编程String Aptitude问答:在本节中,您将找到有关字符串的C Aptitude问答,String是字符集,与String相关的Aptitude问答在这里可以找到。

1) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
int val=0;
char str[]="IncludeHelp.Com";
val=strcmp(str,"includehelp.com");
printf("%d",val);
return 0;
}
  1. 0

  2. 1

  3. -1

  4. Error

Answer
Correct Answer - 3
-1
Strings are not equal, hence strcmp will return -1.

1)以下程序的输出是什么?

  1. 0

  2. 1个

  3. -1

  4. 错误

回答
正确答案-3
-1
字符串不相等,因此strcmp将返回-1。

2) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
char str[];
strcpy(str,"Hello");
printf("%s",str);
return 0;
}
  1. Hello

  2. Error

  3. No Output

  4. Null

Answer
Correct Answer - 2
Error: 'str' Unknown Size
At the time of str declaration, size is empty, it may be possible when you are initializing string with declaration (like char str[]="Hello";

2)以下程序的输出是什么?

  1. 你好

  2. 错误

  3. 无输出

  4. 空值

回答
正确答案-2
错误:“ str”未知大小
在str声明时,size为空,当您使用声明初始化字符串时(例如char str [] =“ Hello”;

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }
3) What will be the output of following program ?

#include <stdio.h>
int main()
{
char str[8]="IncludeHelp";
printf("%s",str);
return 0;
}

  1. IncludeHelp

  2. IncludeH

  3. Error

  4. No Output

Answer
Correct Answer - 3
Error: Too many initializers/ array bounds overflow.

3)以下程序的输出是什么?

  1. 包括帮助

  2. 包含H

  3. 错误

  4. 无输出

回答
正确答案-3
错误:初始化程序/数组边界过多。

4) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
char str1[]="IncludeHelp",str2[]=".Com";
printf("%s",str1+strlen(str2));
return 0;
}
  1. IncludeHelp.Com

  2. udeHelp

  3. Error

  4. IncludeHelp4

Answer
Correct Answer - 2
udeHelp
Look the expression str1+strlen(str2)=> str1+4, since str1 is a character array, and str1+4 will point 4th index of str1, then udeHelp will print.

4)以下程序的输出是什么?

  1. IncludeHelp.Com

  2. udeHelp

  3. 错误

  4. 包括帮助4

回答
正确答案-2
udeHelp
查看表达式str1 + strlen(str2)=> str1 + 4,因为str1是一个字符数组,并且str1 + 4将指向str1的第4个索引,然后将输出udeHelp。

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }
5) What will be the output of following program ?

#include <stdio.h>
int main()
{
char str[]="Hello%s%dFriends";
printf(str);
printf("\n");
printf("%s",str);
return 0;
}

  1. HelloFriends
    HelloFriends

  2. Hello%s%dFriends
    Hello%s%dFriends

  3. Hello(null)0Friends
    Hello%s%dFriends

  4. Garbage Value

Answer
Correct Answer - 3
Hello(null)0Friends
Hello%s%dFriends

printf("%s",str); prints all string, but printf(str) prints the value instead of %s, %d .. etc (default value for %s is null and %d is 0.

5)以下程序的输出是什么?

  1. 你好朋友
    你好朋友

  2. 你好%s%dFriends
    你好%s%dFriends

  3. 您好(空)0个朋友
    你好%s%dFriends

  4. 垃圾价值

回答
正确答案-3
您好(空)0个朋友
你好%s%dFriends
printf(“%s”,str); 打印所有字符串,但printf(str)打印该值,而不是%s,%d等。(%s的默认值为null,%d为0。

6) What will be the output of following program ?

#include <stdio.h>
int main()
{
int i;
char str[]="IncludeHelp";
for(i=0;str[i]!='\0';i++)
{
putchar(str[i]);
putchar('*');
}
return 0;
}

Answer
I*n*c*l*u*d*e*H*e*l*p*
.

6)以下程序的输出是什么?

回答
I * n * c * l * u * d * e * H * e * l * p *

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }
7) What will be the output of following program ?

#include <stdio.h>
int main()
{
char str[]="value is =%d";
int a='7';
str[11]='c';
printf(str,a);
return 0;
}
  1. value is =%d

  2. value is =%c

  3. value is =55

  4. value is =7

Answer
Correct Answer - 4
value is =7
We can assign '7' into integer variable a, a will be 55, but str[11]='c' statement will replace 11th character of str 'd' to 'c', hence str will be "value is =%c.
and statement printf(str,a); will print "value is=7".

7)以下程序的输出是什么?

  1. 值是=%d

  2. 值是=%c

  3. 值是= 55

  4. 值= 7

回答
正确答案-4
值= 7
我们可以将'7'分配给整数变量a,a将为55,但是str [11] ='c'语句会将str'd'的第11个字符替换为'c',因此str将为“ value is =%c 。
和语句printf(str,a); 将显示“值is = 7”。

8) What will be the output of following program ?

#include <stdio.h>
int main()
{
char result,str[]="\0IncludeHelp";
result=printf("%s",str);
if(result)
printf("TRUE");
else
printf("FALSE");
return 0;
}
  1. \0IncludeHelpTRUE

  2. \0IncludeHelpFALSE

  3. Error

  4. FALSE

Answer
Correct Answer - 4
FALSE
str[]="\0IncludeHelp", str will be terminated by \0.

8)以下程序的输出是什么?

  1. \ 0IncludeHelpTRUE

  2. \ 0包括HelpFALSE

  3. 错误

回答
正确答案-4

str [] =“ \ 0IncludeHelp”,str将以\ 0终止。

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }
9) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
if( printf("Hello") == strlen("Hello") )
printf("...Friends");
else
printf("...Enemies");
return 0;
}
  1. Hello...Friends

  2. Hello...Enemies

  3. ...Friends

  4. ...Enemies

Answer
Correct Answer - 1
Hello...Friends
Statement printf("Hello") will print "Hello" and return 5, and statement strlen("Hello") will return total number of characters (5) , hence condition is true.

9)以下程序的输出是什么?

  1. 你好朋友

  2. 你好...敌人

  3. ...朋友

  4. ...敌人

回答
正确答案-1
你好朋友
语句printf(“ Hello”)将打印“ Hello”并返回5,语句strlen(“ H​​ello”)将返回字符总数(5),因此条件为true。

10) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
char s1[]="IncludeHelp";
char s2[10];
strncpy(s2,s1,5);
printf("%s",s2);
return 0;
}
  1. Inclu

  2. IncluGARBAGE_VALUE

  3. Error

  4. IncludeHelp

Answer
Correct Answer - 2
IncluGARBAGE_VALUE
strncpy is used to copy number of characters from one string to another...
strncpy(s2,s1,5) will move 5 characters from s1 to s2, but there is no NULL ('\0') character to terminate the string s2...IncluGARBAGE_VALUE will print.

10)以下程序的输出是什么?

  1. 包含

  2. IncluGARBAGE_VALUE

  3. 错误

  4. 包括帮助

回答
正确答案-2
IncluGARBAGE_VALUE
strncpy用于将字符数从一个字符串复制到另一字符串...
strncpy(s2,s1,5)将5个字符从s1移至s2,但是没有NULL('\ 0')字符可终止字符串s2。 将显示IncluGARBAGE_VALUE。

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }
11) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
char str[50]="IncludeHelp";
printf("%d...%d",strlen(str),sizeof(str));
return 0;
}
  1. 50...50

  2. 11...50

  3. 11...11

  4. 50...11

Answer
Correct Answer - 2
11...50
strlen returns the number of characters, and sizeof(str) returns total occupied size by str.

11)以下程序的输出是什么?

  1. 50 ... 50

  2. 11 ... 50

  3. 11 ... 11

  4. 50 ... 11

回答
正确答案-2
11 ... 50
strlen返回字符数, sizeof(str)返回按str占用的总大小。

12) What will be the output of following program ?

#include <stdio.h>
int main()
{
char *str="IncludeHelp";
while(*str)
printf("%s\n",str++);
return 0;
}

  1. IncludeHelp
    IncludeHel
    IncludeHe
    ..
    I

  2. IncludeHelp
    ncludeHelp
    cludeHelp
    ..
    P

  3. ERROR

  4. IncludeHelp

Answer
Correct Answer - 2

12)以下程序的输出是什么?

#include <stdio.h>
int main()
{
char *str="IncludeHelp";
while(*str)
printf("%s\n",str++);
return 0;
}

  1. 包括帮助
    包括Hel
    包括他
    ..
    一世

  2. 包括帮助
    nclude帮助
    cludeHelp
    ..
    P

  3. 错误

  4. 包括帮助

回答
正确答案-2

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }
13) What will be the output of following program ?

#include <stdio.h>
#define string char*
int main()
{
string myName="IncludeHelp";
printf("My name is =%s",myName);
return 0;
}
  1. IncludeHelp

  2. Error

  3. char*

  4. myName

Answer
Correct Answer - 1
IncludeHelp
string will be replaced by char *.

13)以下程序的输出是什么?

  1. 包括帮助

  2. 错误

  3. 字符*

  4. 我的名字

回答
正确答案-1
包括帮助
字符串将被替换为char *。

14) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main()
{
printf("%d...%d",sizeof("Hello"),strlen("Hello"));
return 0;
}
  1. 5...5

  2. 6...6

  3. 5...6

  4. 6...5

Answer
Correct Answer - 4
6...5
sizeof operator returns the size of the string including NULL character, and strlen returns the number of characters stored in string.

14)以下程序的输出是什么?

  1. 5 ... 5

  2. 6 ... 6

  3. 5 ... 6

  4. 6 ... 5

回答
正确答案-4
6 ... 5
sizeof运算符返回字符串的大小(包括NULL字符),而strlen返回存储在字符串中的字符数。

15) What will be the output of following program ?

#include <stdio.h>
#include <string.h>
int main(){
char str[]="Ihelp";
while(str+strlen(str))
printf("*");
return 0;
}
  1. ERROR

  2. No output

  3. ***... infinite times

  4. *

Answer
Correct Answer - 3
***... infinite times
str+strlen(str) in this expression str is a pointer that return memory address and str+strlen(str) = str+5, also an address (integer value), so expression str+strlen(str) will return non zero value.

15)以下程序的输出是什么?

  1. 错误

  2. 无输出

  3. *** ...无限次

  4. *

回答
正确答案-3
*** ...无限次
STR + strlen的(STR)在这个表达式str是一个指针返回存储器地址和STR + strlen的(STR)= STR + 5,也是一个地址(整数值),所以表达STR +的strlen(STR)将返回非零值。

翻译自: https://www.includehelp.com/c-programs/c-strings-aptitude-questions-and-answers.aspx

c-style字符字符串

c-style字符字符串_C字符串-能力问题与解答相关推荐

  1. android 数组赋值字符串_c语言中的字符数组与字符串

    1.字符数组的定义与初始化 字符数组的初始化,最容易理解的方式就是逐个字符赋给数组中各元素. char str[10]={ 'I',' ','a','m',' ','h','a','p','p','y ...

  2. python基本字符_Python基本字符串,基础,之

    一:字符串 很多人初学编程时,总是担心自己数学不行,潜意识里认为数学好才能编程.实际上,大多数程序员打交道最多的是"字符串"而不是"数字".因为,编程是用来解决 ...

  3. C语言试题四十五之把第1到第p个字符,平移到字符串的最后,把第p+1到最后的字符移到字符串的前部。

    1. 题目 请编写一个函数function,它的功能是:把第1到第p个字符,平移到字符串的最后,把第p+1到最后的字符移到字符串的前部. 2 .温馨提示 C语言试题汇总里可用于计算机二级C语言笔试.机 ...

  4. python用什么方式可以打印换行字符串_字符串是一个连续的字符序列,用________方式打印出可以换行的字符串。...

    [多选题]关于赋值语句的作用,错误的描述是( ) [多选题]Python中布尔变量的值为( ) [多选题]关于 Python 语言的注释,以下选项中描述正确的是( ) [其它]根据CAD原文件绘制别墅 ...

  5. java数值型转字符型_Java中数值型,字符型及字符串的相互转换

    Java中数值型,字符型及字符串的相互转换由广州疯狂软件教育java培训分享: 刚开始学习Java不就前些时日被转换问题搞得有点凌乱在这里整理一下. 1.字符型与数值型之间的转换 (1)要将一个整数转 ...

  6. python从右向左第三个字符_字符串是一个字符序列,例如,字符串s,从右侧向左第3个字符用________索引。...

    [判断题]已知 x, y = 3, 5,那么执行x, y = y, x 之后,x的值为15. [多选题]Python 中对变量描述正确的选项是( ) [单选题]字符串是一个连续的字符序列,用_____ ...

  7. C# 字符串格式化_C# 字符串格式化整理

    一.C# 字符串格式化_C# 字符串格式化整理 使用方式1:  xxx.ToString(xxxx) 使用方式2:string.Format(xxxx,xxx)  1.占位符格式化 零占位符:固定位数 ...

  8. python中替换字符串中字符_python替换字符串中的某个字符

    python_split_strip_replace使用方法 使用python时会经常要对字符串做一些处理,比如:分割字符串.去掉空格.替换字符串 中的某个字符等,下面介绍下这几个功能的使用. 一.  ...

  9. 最长不含重复字符的子字符串

    请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 " ...

最新文章

  1. php删除指定对象的属性及属性值
  2. 深度学习有哪些trick?
  3. 如何让控件span的id调用ajax_微服务架构之「 调用链监控 」
  4. php热门标签,PHP显示最流行的标签
  5. androidstudio build tools安装_如何导入Android Studio(AS)项目
  6. Introdution to 3D Game Programming With DirectX11 第11章 习题解答
  7. Java学习笔记_类和对象
  8. html4的语法,HTML——语法
  9. java 模拟栈底层用数组_java用数组模拟栈
  10. NFA转DFA程序设计
  11. dell r740如何做raid_数据存储之七种RAID浅析
  12. qt creator纯C或C++项目在windows下的命令行中文乱码解决
  13. 51单片机多种方式点亮LED
  14. python笔记:python中 | ^表示什么意思
  15. ubuntu20.04下源码安装hyperscan库安装记录
  16. Excel多级下拉菜单的制作
  17. 执行maven install 报如下错是什么原因呢?
  18. 自然语言处理NLP开源软件工具包
  19. 文本分类---逻辑回归(1)
  20. python爬虫 网页表格

热门文章

  1. VS2017安装配置Qt
  2. CTFHUB《Web-信息泄露-备份文件下载》网站源码,
  3. java五星好评点评器_亲,麻烦给个五星好评!—RatingBar
  4. python 基因序列提取_科学网—简单的Python脚本提取对应位置基因序列(fasta文件) - 王彬忠的博文...
  5. 室内定位算法_001:室内定位算法技术咨询服务工作室简介(更新)
  6. simulink中mask设置_(实现BPSK学习Verilog)1. Simulink仿真实现
  7. mac os和linux和安卓,在我的安卓手机里,安装Windows和macOS系统
  8. f3arra1n3.4.1版本_Sysmon v11.1新版本功能测试报告
  9. spark环境搭建java_Spark MLlib 环境搭建超详细教程
  10. 新手攻略熔炉_我的世界攻略:生存模式新手攻略