Class 16: Strings Flashcards

1
Q

A character array terminated by null character

A

String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Anything enclosed in double quotation marks. Null character is automatically provided by compiler and stored in memory as character string.

A

String literal/string constant

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Initializing a character array

A

char string [] = “Hi my name is Tanvi”;
char string2[60] = “Hi my name is Tanvi”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

char car[10] = “Tata”;
car == ?

A

&car[0]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

scanf(“%d %d”, &a, &b)

A

read two integers from the standard input. The space in the format string %d %d tells scanf to expect whitespace (spaces, tabs, or newlines/enters) between the two numbers. When you press Enter after typing the first number, it’s interpreted as whitespace, and scanf proceeds to read the second integer. The values are then stored in the integer variables a and b, respectively.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

scanf(“%[^\n]s”, name);

A

The scanf(“%[^\n]s”, name) function reads an entire line, including spaces, until a newline (\n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Strings which are array of characters

A

Read-write strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Compiler will insert NULL terminator when we define string with “”

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Compiler will insert NULL terminator when we define a string as a array of characters

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

String *string1 = “GO Bucks”;
Char string2[10] “Go Bucks”;
Which string can change?

A

String 1 can change because it is a pointer to string literal. “GoBucks” CANNOT
String2 cannot change because it is a constant pointer to char (name or array is always a pointer to the first element) however “Go Bucks” CAN.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In all but one of these options, the compiler will place a null terminating character at the end of the string
1. Char label1[5] = {‘t’,’a’,’n’,’u’};
2. Char lablel2[] = {‘t’,’a’,’n’,’u’}
3. Char label3[10] = “container”
4. char label4[] = “container”;

A

All declarations will be null terminated expect the lablel2 array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly