string functions Flashcards

1
Q

What are examples of array initialization in C and how does it differ from Java?

A

int a[10]; int a[] = {1,2,3} in Java an array was descried like this: int[] a = {1,2,3}; int a = new int[]; AND you don’t need to use new

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

What is the terminating character for Strings? (in C) How does it affect the size of the char array?

A

‘\0’ The character uses up one of the spaces of the length

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

What does int strlen(s) do?

A

returns length of string s unit \0

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

What does strcpy(dst, src) do?

A

copies string characters from src into dst

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

What does: char* strdup(s), do?

A

allocates and returns a copy of s

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

what does: strcat(s1, s2), do?

A

Concatenates s2 onto the end of s1 (puts \0)

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

What does: int strcmp(s1, s2), do?

A

returns < 0 if s1 comes before s2 in ABC order returns > 0 if s1 comes after s2 in ABC order returns 0 if s1 and s2 are the same

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

what does: int strchr(s, c), do?

A

returns index of first occurrence of c in s

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

What does: int strstr(s1, s2), do?

A

returns index of first occurrence of s2 in s1

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

What does: char* strtok(s, delim), do?

A

breaks apart s into tokens by delimiter delim

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

what is the difference with: strncpy, strncat, strncmp

A

lengh-limited version of above the same functions?

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