Shared Flashcard Set

Details

Systems Terms: Strings and I/O Streams
Terms from Lecture 8 of my Systems class
13
Computer Science
Graduate
02/15/2025

Additional Computer Science Flashcards

 


 

Cards

Term
What happens here?

char str1[] = "Hello\0everyone!";
char str2[] = "Happy Friday!";

printf(str1);
Definition
Hello
Term
What is wrong with this code? (4)

char str1[] = "Hello\0everyone!";
printf(%s, str1[6];
Definition
1. %s wants a pointer to a character, but str1[6] gives it an integer
2. (characters are upgraded to integers!). 3. To get a character pointer, we need to do &str1[6].
4. Or str1 + 6.
Term
Difference between sizeof and strlen
Definition
Sizeof gets the size in memory, which includes \0. Strlen does not include \0.
Term
Difference between char str[] = "Hello World!" and char *str = "Hello World!"
Definition
The first is mutable, the second is an immutable string literal
Term
What is the difference between strcmp and strncmp? Strcopy and strncopy?
Definition
Strncmp and strncopy specify a fixed length
Term
What is wrong with this code?

char str1[] = "Hello World!";
char str2[] = str1;
Definition
str2[] is initialized as a constant pointer. That means it can't point at anything else.
Term
What is wrong with this code?

char str1[] = "Hello World!";
char str2[12];
strcpy(str2, str1);
Definition
Char str2[12] specifies the length of the array, not the size. Str1 has a size of 13 because of the null character, so when it gets copied until str2, the null character is not copied. That means the null character is placed outside the bounds of str2.
Term
Why doesn't this code work?

char *amazing_str = "Gotta get down on Friday!";
strcpy(amazing_str, "Matthew");
Definition
Amazing_str has been declared as an immutable string literal
Term
Rules for char x[int]
Definition
You can put in a string with size less than int, but not greater than int
Term
When to use:
char *my_string
char other_str []
char amazing_str[128]
Definition
Use * when you don't need to change anything. Use [] when you might want to change the characters in place, but don't anticipate having to put new things in. Use [128] (or some other large number) when you anticipate having to add new things in.
Term
Difference between strcpy and strcat
Definition
Strcpy overrides what is in the destination string, strcat just attaches to the end of it
Term
Program to get age input from the user
Definition
printf("Please enter your age: ");
int age;
scanf("%d", &age);
Term
What does this mean?
ls -l / > list_of_files.txt
Definition
Directs stdout to a file
Supporting users have an ad free experience!