Font size
WorksheetsFor David
Total questions: 69
Worksheet time: 6hrs 45mins
How long has C been around?
(1978-1986)
(1969-1973)
(1956-1974)
(1897-1920)
This is a collection of instructions that perform some purpose, solves a specific problem.
computing
coding
program
javascript
Windows, MacOS, Unix are examples of these.
operating system
websites
applications
control system
The first sub-step when compiling where certain “administrative” things are taken care of before any compiling takes place (for example a #define, which we’ll talk about later). So, for now, think of this sub-step as “filling in the blanks” before compiling. (.i file)
processor
post-processor
pre-processor
algorithm
This is the process of analyzing & translating the program from the C program language to a form the computer can understand (machine language); creates an executable.
compilation
assembly
processor
linker
These are the (low-level) types of instructions that the computer (processor) understands. They are not human readable; they are machine dependent - only worked on the machine that it was developed for (not portable).
(a)
After compiling a program but before it can be executed, this is the step that links or adds to the object code any other code being included with the program (from the #includes or from the other program files that are all being compiled together) which then produces the executable program
(a)
These are logical errors, e.g. using a variable that hasn’t been declared yet.
(a)
This refers to the approach or steps taken to solve the problem, to show the logic for the program before you start coding.
(a)
These are language-specific omissions/errors, e.g., missing a semi-colon where one is required.
(a)
The second sub-step when compiling where the programming language instructions are broken down into assembly language instructions first (.s file) and then converts each assembly language instruction into binary code, or object code (.o file).
(a)
These are also low-level types of instructions that, starting in the early 1950s, allowed the programmer to use a somewhat more English-like way of writing instructions by using abbreviations, or mnemonic codes, to refer to the bit-patterns.
(a)
This person was the one who had the idea that programs could be written in more English-like statements than assembly and machine language; also created the first compiler, among many other things.
Howard H. Aiken
Grace Murray Hopper
Alan Turing
John von Neumann
/* why won’t this program compile? */
#include <stdio.h>
int main(void) {
int inputNumber;
int a = 10, b = 20;
float c = 4.2, d = 3.0
printf(“Enter an integer \n”);
scanf(“%d”, inputNumber);
printf(“The sum of a and b is \n”, sum);
printf(“a multiplied by your number is %i\n”, a * inputNumber);
printf(“c added to d is %i\n”, c + d);
return 0;
}
missing comma
missing semi-colon
missing &
replace sum with add
missing %i
/* why won’t this program compile? */
#include <stdio.h>
int main(void) {
int inputNumber;
int a = 10, b = 20;
float c = 4.2, d = 3.0
printf(“Enter an integer \n”);
scanf(“%d”, inputNumber);
printf(“The sum of a and b is \n”, sum);
printf(“a multiplied by your number is %i\n”, a * inputNumber);
printf(“c added to d is %i\n”, c + d);
return 0;
}
sum is not declared
missing *
missing ""
wrong format string
/* why won’t this program compile? */
#include <stdio.h>
int main(void) {
int inputNumber;
int a = 10, b = 20;
float c = 4.2, d = 3.0
printf(“Enter an integer \n”);
scanf(“%d”, inputNumber);
printf(“The sum of a and b is \n”, sum);
printf(“a multiplied by your number is %i\n”, a * inputNumber);
printf(“c added to d is %i\n”, c + d);
return 0;
}
What should the format string be instead
int a = 100, b = 2, c = 25, d = 3, e = 1;
int result;
result = e + c % d
printf (“%d”, result);
(a)
int a = 100, b = 2, c = 25, d = 3, e = 1;
int result;
result = -a + d;
printf (“%d”, result);
(a)
int x = 3, y = 9;
int result;
result = x + 5 * y / 3 * x;
printf (“%d”, result);
(a)
int x = 3, y = 9;
int result;
result = x + ((5 * y) / (3 * x));
printf (“%d”, result)
(a)
int a = 100, b = 2, c = 25, d = 3, e = 1;
int result;
printf (“%.2f”, (float)c / b);
(a)
int a = 100, b = 2, c = 25, d = 3, e = 1;
int result;
printf (“%d”, b++);
(a)
What is another way of writing these?
a += 10;
c /= 6;
(put a space ex: z = r - 69; )
(a)
Which of the following is the same as:
a *= b + c;
a = a * b + c;
OR
a = a * (b + c);
(a)
What will be printed out to the screen?
int a = 10;
int b = ++a * 10;
printf(“%d %d”, a, b);
(space between each number)
(a)
What will be printed out to the screen?
int a = 10;
int b = a++ * 10;
printf(“%d %d”, a, b);
(a)
11310 = (a) 2
110012 = (a) 10
1010011100002 = (a) 16
1011110110001110102 = (a) 8
B38C616 = (a) 2
726318 = (a) 2
20210 = (a) 8
20210 = (a) 16
What will be printed out to the screen?
int a = 25, b = 5;
if (a = b)
printf (“Values of both variables are equal \n”);
else
printf (“Values of both variables are different \n”);
(a)
What will be printed out to the screen?
int a = 25, b = 0;
if (a = b)
printf (“Values of both variables are equal \n”);
else
printf (“Values of both variables are different \n”);
(a)
Evaluate the following expression.
! ( 1 && ! ( 0 || 1 ) )
True
False
Suppose string str1 is initially Hello and str2 is Hi
After strcpy(str2, “ there”) and then strcat(str1, str2)
what is str1?
(a)
Suppose string str1 is initially Hello and str2 is Hi
After strcpy(str2, “ there”) and then strcat(str1, str2)
[ if str2 is declared with length >= 7 and str1 is declared with length >= 9 ]
What value is returned by calling strlen(str1)
(a)
Suppose string str1 is initially Hello and str2 is Hi
After strcpy(str2, “ there”) and then strcat(str1, str2)
[ if str2 is declared with length >= 7 and str1 is declared with length >= 9 ]
How many total characters are in str1?
(a)
Suppose string str1 is initially Hello and str2 is Hi
After strcpy(str1, str2) and then strcpy(str2, “Bye”)
what is str1?
(a)
Suppose string str1 is initially Hello and str2 is Hi
After strcpy(str1, str2) and then strcpy(str2, “Bye”)
[ if str2 is declared with length >= 4 ]
what is str2?
(a)
Suppose string str1 is initially Hello and str2 is Hi
After strcpy(str1, str2) what is str1?
(a)
Write a statement that assigns to userName the name Sarah
(a)
Declare a C-string called userName
(a)
Look at the following code:
char words[] = “Programming is my favorite class!”;
int i = 17;
words[i+2] = ‘\0’;
words[i+1] = ‘!’;
words[i] = ‘n’;
words[i-1] = ‘u’;
words[i-2] = ‘f’;
What would the condition be (for example, in an if statement) if you wanted to test whether the 18th character in the array words is the charactr n
(a)
Look at the following code:
char words[] = “Programming is my favorite class!”;
int i = 17;
words[i+2] = ‘\0’;
words[i+1] = ‘!’;
words[i] = ‘n’;
words[i-1] = ‘u’;
words[i-2] = ‘f’;
If the above lines of code were executed in the order that they appear, what would the following printf statements produce?
printf (“%s”, words);
(a)
Look at the following code:
char words[] = “Programming is my favorite class!”;
int i = 17;
words[i+2] = ‘\0’;
words[i+1] = ‘!’;
words[i] = ‘n’;
words[i-1] = ‘u’;
words[i-2] = ‘f’;
If the above lines of code were executed in the order that they appear, what would the following printf statements produce?
a. printf(“%c”, words[18]);
(a)
How many characters are in this array?
char word1[] = {“CS for all”};
(a)
How many characters are in this array?
char word1[] = {‘a’, ‘l’, ‘l’, ‘ ‘, ‘i’, ‘n’};
(a)
Declare a C-string called myString that contains 25 characters.
(a)
Declare and initialize a C-string called word1 that contains the word Hello!
(a)
Write code that changes the string called word1 from the previous question to the following:
a. assign the character p to the 4th element in the array
(a)
Write code that changes the string called word1 from the previous question to the following:
assign the character ! to the 5th element in the array
(a)
Write code that changes the string called word1 from the previous question to the following:
What would be the result of the following?
printf(“%s”, word1);
(a)
Write code that changes the string called word1 from the previous question to the following:
What would be the result of this statement?
printf(“%4s”, word1);
printf(“%10s”, word1);
(a)
Is this a valid array declaration?
int array2[] = {1, 2, 3, 4, 5};
No
Yes
Given the following array declaration, what is maxScores[3]?
int maxScores[4] = {20, 20, 100, 50};
(a)
What would print to the screen with this code?
int array3[5] = {1, 2, 3};
int i;
for (i = 1; i < 5; i++)
printf(“%d “, array3[i]);
(a)
What would print to the screen with this code?
int array3[5] = {‘1’, ‘2’, ‘3’};
int i;
for (i = 0; i < 5; i++)
printf(“%d “, array3[i]);
(a)
After the following code executes, what would the values of the following be: num[2], num[29], num[80]
int num[100], i = 0;
while(i < 100) {
num[i] = 2 * i + 3;
i += 2;
}
(a)
Which of the following allocates an array of 10 floats named grades?
a. float array[10] grades;
b. float [10] grades;
c. float grades[10];
d. float array grades 10;
If grades is an array of 10 floats, what is the type of grades?
array of float
bool
float
int
If grades is an array of 10 floats, what is the type of grades[0]?
bool
array of float
float
int
If ages is an array of 10 ints, what is the type of ages[3] < 21?
int
array of int
bool
float
What value is assigned to x when y is 10?
x = 25;
if (y != (x – 10))
x = x – 10;
else
x = x / 2;
(a)
What value is assigned to x when y is 10?
x = 25;
if (y < 15)
if (y >= 0)
x = 5 * y;
else
x = 2 * y;
else
x = 3 * y;
(a)
What is the final value of x if the initial value of x is 1?
if (x >= 0)
x = x + 1;
else if (x >= 1)
x = x + 2;
(a)
What is the final value of x if the initial value of x is 1?
if (x >= 0)
x = x + 1;
if (x >= 1)
x = x + 2;
(a)
