Quiz 2 - CS50
Quiz 2 - CS50
Assuming the text message is represented using ASCII, what sequence of bits
(or, if you prefer, decimal digits) did you actually receive?
b) Suppose that you've just received the below text message instead.
Assuming the text message is represented using ASCII, what sequence of bits
(or, if you prefer, decimal digits) did you actually receive?
Answers
a) The sequence of bits would be: 1001000 1001001 0100001 aka 72,73, 33
b) The sequence of bits would be: 0110111 0110010 0110111 0110001 0110001
0110001 aka. 55 50 , 55, 51 ,51 51
c) Because in ASCII numbers are not represented by as their bit counterparts and
each digit is represented as an individual character therefore numbers from 0-9
are assigned values 48-57.
Question 2 of 3
Recall that, in lecture, we saw how to write programs in C that support command-line
arguments. To do so, we modified the program's main function to take two arguments:
argc and argv.
Answers
a) Maybe one could be the make program as it uses the command line argument to
know the name of the c program file to make the compiled code
b) argc is the argument counter which counts/denotes the number of arguments
given, it itself is an integer variable
c) argv is used as a parameter to represent commandline arguments as an array
list of arguments, as char or arrays of chars, so strimngs, or arrays of strings
from argv[0] to argv[argc-1] the last argument
Question 3 of 3
Recall that, in lecture, we saw the following two for loops, both of which print the
characters of a string, s, one character per line.
Version 1 Version 2
for (int i = 0; i < strlen(s); i++) for (int i = 0, n = strlen(s); i < n; i++)
{ {
printf("%c\n", s[i]); printf("%c\n", s[i]);
} }
Answers