日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c-style字符字符串_C字符串-能力问题与解答

發(fā)布時(shí)間:2025/3/11 编程问答 10 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c-style字符字符串_C字符串-能力问题与解答 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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問答:在本節(jié)中,您將找到有關(guān)字符串的C Aptitude問答,String是字符集,與String相關(guān)的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; }
  • 0

  • 1

  • -1

  • Error

  • Answer Correct Answer - 3
    -1
    Strings are not equal, hence strcmp will return -1. 1)以下程序的輸出是什么?
  • 0

  • 1個(gè)

  • -1

  • 錯(cuò)誤

  • 回答 正確答案-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; }
  • Hello

  • Error

  • No Output

  • 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)以下程序的輸出是什么?
  • 你好

  • 錯(cuò)誤

  • 無輸出

  • 空值

  • 回答 正確答案-2
    錯(cuò)誤:“ str”未知大小
    在str聲明時(shí),size為空,當(dāng)您使用聲明初始化字符串時(shí)(例如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; }
  • IncludeHelp

  • IncludeH

  • Error

  • No Output

  • Answer Correct Answer - 3
    Error: Too many initializers/ array bounds overflow.
    3)以下程序的輸出是什么?
  • 包括幫助

  • 包含H

  • 錯(cuò)誤

  • 無輸出

  • 回答 正確答案-3
    錯(cuò)誤:初始化程序/數(shù)組邊界過多。
    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; }
  • IncludeHelp.Com

  • udeHelp

  • Error

  • 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)以下程序的輸出是什么?
  • IncludeHelp.Com

  • udeHelp

  • 錯(cuò)誤

  • 包括幫助4

  • 回答 正確答案-2
    udeHelp
    查看表達(dá)式str1 + strlen(str2)=> str1 + 4,因?yàn)閟tr1是一個(gè)字符數(shù)組,并且str1 + 4將指向str1的第4個(gè)索引,然后將輸出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; }
  • HelloFriends
    HelloFriends

  • Hello%s%dFriends
    Hello%s%dFriends

  • Hello(null)0Friends
    Hello%s%dFriends

  • 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)以下程序的輸出是什么?
  • 你好朋友
    你好朋友

  • 你好%s%dFriends
    你好%s%dFriends

  • 您好(空)0個(gè)朋友
    你好%s%dFriends

  • 垃圾價(jià)值

  • 回答 正確答案-3
    您好(空)0個(gè)朋友
    你好%s%dFriends
    printf(“%s”,str); 打印所有字符串,但printf(str)打印該值,而不是%s,%d等。(%s的默認(rèn)值為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; }
  • value is =%d

  • value is =%c

  • value is =55

  • 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)以下程序的輸出是什么?
  • 值是=%d

  • 值是=%c

  • 值是= 55

  • 值= 7

  • 回答 正確答案-4
    值= 7
    我們可以將'7'分配給整數(shù)變量a,a將為55,但是str [11] ='c'語句會(huì)將str'd'的第11個(gè)字符替換為'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");elseprintf("FALSE");return 0; }
  • \0IncludeHelpTRUE

  • \0IncludeHelpFALSE

  • Error

  • FALSE

  • Answer Correct Answer - 4
    FALSE
    str[]="\0IncludeHelp", str will be terminated by \0. 8)以下程序的輸出是什么?
  • \ 0IncludeHelpTRUE

  • \ 0包括HelpFALSE

  • 錯(cuò)誤

  • 回答 正確答案-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");elseprintf("...Enemies");return 0; }
  • Hello...Friends

  • Hello...Enemies

  • ...Friends

  • ...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
    你好朋友
    語句printf(“ Hello”)將打印“ Hello”并返回5,語句strlen(“ H??ello”)將返回字符總數(shù)(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; }
  • Inclu

  • IncluGARBAGE_VALUE

  • Error

  • 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)以下程序的輸出是什么?
  • 包含

  • IncluGARBAGE_VALUE

  • 錯(cuò)誤

  • 包括幫助

  • 回答 正確答案-2
    IncluGARBAGE_VALUE
    strncpy用于將字符數(shù)從一個(gè)字符串復(fù)制到另一字符串...
    strncpy(s2,s1,5)將5個(gè)字符從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; }
  • 50...50

  • 11...50

  • 11...11

  • 50...11

  • Answer Correct Answer - 2
    11...50
    strlen returns the number of characters, and sizeof(str) returns total occupied size by str. 11)以下程序的輸出是什么?
  • 50 ... 50

  • 11 ... 50

  • 11 ... 11

  • 50 ... 11

  • 回答 正確答案-2
    11 ... 50
    strlen返回字符數(shù), 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; }
  • IncludeHelp
    IncludeHel
    IncludeHe
    ..
    I

  • IncludeHelp
    ncludeHelp
    cludeHelp
    ..
    P

  • ERROR

  • IncludeHelp

  • Answer Correct Answer - 2
    12)以下程序的輸出是什么? #include <stdio.h> int main() {char *str="IncludeHelp";while(*str)printf("%s\n",str++);return 0; }
  • 包括幫助
    包括Hel
    包括他
    ..
    一世

  • 包括幫助
    nclude幫助
    cludeHelp
    ..
    P

  • 錯(cuò)誤

  • 包括幫助

  • 回答 正確答案-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; }
  • IncludeHelp

  • Error

  • char*

  • myName

  • Answer Correct Answer - 1
    IncludeHelp
    string will be replaced by char *. 13)以下程序的輸出是什么?
  • 包括幫助

  • 錯(cuò)誤

  • 字符*

  • 我的名字

  • 回答 正確答案-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; }
  • 5...5

  • 6...6

  • 5...6

  • 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)以下程序的輸出是什么?
  • 5 ... 5

  • 6 ... 6

  • 5 ... 6

  • 6 ... 5

  • 回答 正確答案-4
    6 ... 5
    sizeof運(yùn)算符返回字符串的大小(包括NULL字符),而strlen返回存儲(chǔ)在字符串中的字符數(shù)。 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; }
  • ERROR

  • No output

  • ***... infinite times

  • *

  • 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)以下程序的輸出是什么?
  • 錯(cuò)誤

  • 無輸出

  • *** ...無限次

  • *

  • 回答 正確答案-3
    *** ...無限次
    STR + strlen的(STR)在這個(gè)表達(dá)式str是一個(gè)指針返回存儲(chǔ)器地址和STR + strlen的(STR)= STR + 5,也是一個(gè)地址(整數(shù)值),所以表達(dá)STR +的strlen(STR)將返回非零值。

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

    c-style字符字符串

    總結(jié)

    以上是生活随笔為你收集整理的c-style字符字符串_C字符串-能力问题与解答的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。