c-style字符字符串_C字符串-能力問題與解答

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”;
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。
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 *
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終止。
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。
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
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字符字符串

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541755.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541755.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541755.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

PHP Smarty template for website

/******************************************************************************* PHP Smarty template for website* 說明&#xff1a;* 之前一直在想將MVC的方式加在PHP做的網站上&#xff0c;這樣比較好處理&#xff0c;相對來說比較好* 處理…

ftp連接oracle服務器,使用SSL加密連接FTP - 架建SSL安全加密的FTP服務器(圖)_服務器應用_Linux公社-Linux系統門戶網站...

四、使用SSL加密連接FTP啟用Serv-U服務器的SSL功能后&#xff0c;就可以利用此功能安全傳輸數據了&#xff0c;但FTP客戶端程序必須支持SSL功能才行。 如果我們直接使用IE瀏覽器進行登錄則會出現圖4顯示的錯誤信息&#xff0c;一方面是以為沒有修改默認的端口21為990&#xff0…

c# 情感傾向_C否則-能力傾向問題與解答

c# 情感傾向C programming if else Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on condition statements – if else, nested if else, ladder if else, conditional operators etc. C語言編程如果有問題&#xff0c;請…

springboot中使用緩存shiro-ehcache

在pom.xml中注入緩存依賴&#xff0c;版本(Sep 09, 2016)spring-context-support 包含支持UI模版&#xff08;Velocity&#xff0c;FreeMarker&#xff0c;JasperReports&#xff09;&#xff0c; 郵件服務&#xff0c; 腳本服務(JRuby)&#xff0c; 緩存Cache&#xff08;EHCa…

oracle 微信公眾號,關于微信公眾號貼代碼的方法

微信公眾號碼上貼代碼一直一來都是個頭疼的問題。吐槽一句&#xff1a;要是后臺編輯器支持markdown就好了。今天教大家用在線markdown排版工具&#xff0c;把代碼完美貼到微信公眾號上。長話短說&#xff0c;今天用到的兩個工具&#xff1a;首先&#xff0c;以一段代碼為例。假…

計算理論 形式語言與自動機_下推式自動機(PDA)| 計算理論

計算理論 形式語言與自動機Pushdown Automaton (PDA) is a kind of Automaton which comes under the theory of Computation that appoints stack. The word Pushdown stands due to the fact that the stack can be pushed down as operations can only work on the elements…

運維人員究竟如何提升價值,持續獲得高薪?

作者簡介&#xff1a;老男孩&#xff0c;北京老男孩IT教育創始人&#xff0c;17年IT經驗&#xff0c;資深Linux實戰專家&#xff0c;IT培訓界實戰派頂尖大師&#xff0c;國內將實戰心理學體系大量注入IT運維培訓領域的第一人&#xff0c;多本IT暢銷圖書作者&#xff0c;51CTO金…

Webservice soap wsdl區別之個人見解

Web Service實現業務訴求&#xff1a;Web Service是真正“辦事”的那個&#xff0c;提供一種辦事接口的統稱。WSDL提供“能辦的事的文檔說明”&#xff1a;對要提供的服務的一種描述格式。我想幫你的忙&#xff0c;但是我要告訴你我都能干什么&#xff0c;以及干這些事情需要的…

java uuid靜態方法_Java UUID nameUUIDFromBytes()方法及示例

java uuid靜態方法UUID類名UUIDFromBytes()方法 (UUID Class nameUUIDFromBytes() method) nameUUIDFromBytes() method is available in java.util package. java.util包中提供了nameUUIDFromBytes()方法 。 nameUUIDFromBytes() method is used to get a UUID constructed fr…

清空 linux 服務器,Linux服務器清理

Why?廢話不多說直接來圖&#xff0c;可以看出磁盤已經快要滿了未清之前What?可以看出mnt文件夾占用的最大&#xff0c;然后進入mnt目錄里通過命令,根據文件大小對該路徑下文件排序du -h --max-depth1我們服務器出現磁盤快滿了的原因是因為&#xff0c;服務器部署了多個tomcat…

Git中的AutoCRLF與SafeCRLF換行符問題

2019獨角獸企業重金招聘Python工程師標準>>> 原文&#xff1a;http://www.cnblogs.com/flying_bat/archive/2013/09/16/3324769.html 最近在使用GitHub&#xff0c;發現不時沒有修改過的文件要提交&#xff0c;對比發現文件全部修改&#xff0c;但找不到不一樣的地方…

stringwriter_Java StringWriter getBuffer()方法與示例

stringwriterStringWriter類的getBuffer()方法 (StringWriter Class getBuffer() method) getBuffer() method is available in java.io package. getBuffer()方法在java.io包中可用。 getBuffer() method is used to get the StringBuffer that holds the present buffer valu…

linux 下郵件服務器,Linux 下搭建Postfix郵件服務器

Linux 下搭建Postfix郵件服務器詳解&#xff1a;1、首先關閉sendmail服務service sendmail stop2、chkconfig sendmail off(關閉開機自啟動)3、修改DNS正解文件&#xff0c;使DNS能夠解析郵箱服務添加下面兩行mail.zhubf.com. IN A 172.17.17.2zhubf.com. IN M…

Java PipedInputStream close()方法與示例

PipedInputStream類close()方法 (PipedInputStream Class close() method) close() method is available in java.io package. close()方法在java.io包中可用。 close() method is used to close this PipedInputStream and free all system resources linked with this stream…

Coreseek Windows下安裝調試

由于項目需要全文檢索&#xff0c;后面就去網上查了下資料&#xff0c;找到了Sphinx【中文是獅身人面像】這個全文檢索引擎&#xff0c;聽說挺好用的&#xff0c;不過沒有中文分詞。后面又去找了一下&#xff0c;找到了Coreseek&#xff0c;一款中文全文檢索/搜索軟件。 一、Sp…

linux sudo命令全稱,linux sudo命令的概念與使用

1.sudo介紹本文引用地址&#xff1a;http://www.eepw.com.cn/article/201610/305498.htmsudo是linux下常用的允許普通用戶使用超級用戶權限的工具&#xff0c;允許系統管理員讓普通用戶執行一些或者全部的root命令&#xff0c;如halt&#xff0c;reboot&#xff0c;su等等。這樣…

java 方法 示例_Java語言環境getISOCountries()方法與示例

java 方法 示例區域設置類getISOCountries()方法 (Locale Class getISOCountries() method) getISOCountries() method is available in java.util package. getISOCountries()方法在java.util包中可用。 getISOCountries() method is used to return an array of string that …

android shape.xml 屬性詳解

轉載源:http://blog.csdn.net/harvic880925/article/details/41850723 一、簡單使用 剛開始&#xff0c;就先不講一堆標簽的意義及用法&#xff0c;先簡單看看shape標簽怎么用。 1、新建shape文件 首先在res/drawable文件夾下&#xff0c;新建一個文件&#xff0c;命名為&#…

linux檢查防火墻是否阻擋端口,淺析linux查看防火墻狀態和對外開放的端口狀態...

1.查看防火墻狀態查看防火墻狀態 systemctl status firewalld開啟防火墻 systemctl start firewalld關閉防火墻 systemctl stop firewalld開啟防火墻 service firewalld start若遇到無法開啟先用&#xff1a;systemctl unmask firewalld.service然后&#xff1a;systemctl star…

Java類class getClasses()方法及示例

類的類getClasses()方法 (Class class getClasses() method) getClasses() method is available in java.lang package. getClasses()方法在java.lang包中可用。 getClasses() method is used to return an array that contains Class objects denoting all the public classes…