click below
click below
Normal Size Small Size show me how
CIS1300
Intro to Programming
| Question | Answer |
|---|---|
| What is the name of the VPN client that students must install and connect to for off-campus access to the University of Guelph network before using SSH to reach SoCS servers? | Cisco AnyConnect VPN Client |
| Which Linux command is used to list the contents of the current directory, including hidden files (those that start with a dot .)? | ls -a |
| To securely copy a C program file named assignment_1.c from her local machine to her ~/cis1300/assignments/a1/ directory on the linux.socs.uoguelph.ca server, what scp command would Michelle use from her local terminal? | scp assignment_1.c michelle@linux.socs.uoguelph.ca:~/cis1300/assignments/a1/ |
| Which Linux command would you use to delete a directory named temp_folder and all the files and subdirectories within it? | rm -r temp_folder |
| What is the correct zip command to create the submission archive a1_1234567.zip? | zip a1_1234567.zip a1/a1_1234567_initial.c a1/a1_1234567_final.c a1/a1_1234567_reflection.pdf |
| Michelle has completed Assignment 1 and created the required zip file. Which scp command would she use from her local machine's terminal to download this zip file to her current local directory? | scp michelle@linux.socs.uoguelph.ca:~/cis1300/assignments/a1_michelle.zip |
| What is the primary purpose of the #include <stdio.h> directive? | To include standard input/output functions like printf() |
| In C, which of the following best describes the role of the main() function? | It is the entry point where program begins execution. |
| To remotely connect to the SoCS Linux servers from your local computer using SSH, what is the correct command syntax? | ssh <username>@<hostname>.socs.uoguelph.ca |
| Michelle wants to download her entire a1 assignment directory to her current local directory. Which scp command, including the recursive option, should she use from her local terminal? | scp -r michelle@linux.socs.uoguelph.ca:~/cis1300/assignments/a1/ |
| To rename a file named old_name.txt to new_name.txt in the same directory, what Linux command would you use? | mv old_name.txt new_name.txt |
| To access the SoCS Linux servers remotely from off-campus, what crucial step must you take before using the ssh command? | Connect to the university's VPN |
| Which arithmetic operator in C is used to find the remainder of a division operation? | % |
| To create a new directory named my_assignment in your current location, what is the correct Linux command? | mkdir my_assignment |
| In C, what is the result of the expression 15 / 4 when both 15 and 4 are integer types? | 3 |
| Which command correctly extracts all files from an archive named michelle.zip into the current directory? | unzip michelle.zip |
| To remotely connect to the SoCS Linux servers from your local computer using SSH, if your username is michelle and the hostname is linux.socs.uoguelph.ca, what is the correct command syntax? | ssh michelle@linux.socs.uoguelph.ca |
| Which Linux command is used to display the full path of your current working directory? | pwd |
| If you declare an integer variable int count; but do not initialize it before its first use, what value will count typically contain? | A random value (often called "garbage") |
| What does the return 0; statement at the end of the main() function conventionally signify? | The program executed successfully. |
| How can you view the list of files inside michelle.zip without actually extracting them? | unzip -l michelle.zip |
| You've written a C program in a file named program.c. To compile it and create an executable file named exec_me, what gcc command would you use? | gcc -o exec_me program.c |
| To securely copy a file named my_notes.txt from your local machine to your ~/cis1300/ directory on the SoCS Linux server, what scp command would you use from your local terminal? | scp my_notes.txt your_username@linux.socs.uoguelph.ca:~/cis1300/ |
| You have completed Assignment 1 and created the required zip file, which scp command would you use from your local machine's terminal to download this zip file to your current local directory? | scp your_username@linux.socs.uoguelph.ca:~/cis1300/assignments/a1_your_student_id.zip |
| Michelle needs to create a new C program file named hello_world.c in her current directory on the SoCS Linux server using the beginner-friendly text editor. What is the correct command to open this file in Nano? | nano hello_world.c |
| Which escape sequence is used within a printf() string to move the cursor to the beginning of the next line? | \n |
| An uninitialized int variable is guaranteed to have a value of 0. (T/F) | False |
| Which of the following is an invalid variable name in C? "1300_cs", "__LINE__", "item_count", "_total" | 1300_cs |
| The printf() format specifier for printing a string (char *) is ____. | %s |
| What is the output of the following code snippet? int i = 10; int j = 5 + i++; printf("i=%d, j=%d\n", i, j); | i = 11, j = 15 |
| In C, which of the following values evaluates to "false"? 0, 1, -1, 'f' | 0 |
| What is the primary difference between a variable and its memory address? | A variable holds a value, while its address is the location in memory where that value is stored. |
| To display the value of a floating-point number (float) followed by an integer (int) in C using printf(), which sequence of format specifiers is correct? | %f %d |
| In C, what is typically considered true when using integers for Boolean logic (without including <stdbool.h>)? | Any non-zero integer value |
| Michelle is writing a program and wants to use explicit bool types. What is the correct way to declare a Boolean variable is_active and set it to true in modern C? | #include <stdbool.h> bool is_active = true; |
| Consider the following C code snippet: int count; printf("The count is: %d\n", count); What is the most likely output or behaviour of this code, and why? | It will print "The count is: " followed by random garbage, as uninitialized local variables hold whatever was in memory previously. |
| What is the shorthand assignment statements for the expression below? x = x + y; | x += y; |
| A common mistake for beginners in C is confusing the assignment operator with a comparison operator. Which operator is used to check if two values are equal? | == |
| Michelle is trying to evaluate a complex Boolean expression. Given: int x = 5; int y = 10; What is the result of !(x > y) || (x == 7 && y != 10) | 1 (true) |
| What is the primary purpose of the sizeof operator in C? | To return the number of bytes a data type or variable occupies in memory. |
| In C, if you perform the operation int result = 25 / 10; What will be the value of result? | 2 |
| What is the output of this code? #include <stdio.h> #include <stdbool.h> int main(void) { printf("%d\n", true == 5); return 0; } | 0 |
| What is the output of the following code snippet? int i = 5; int j = 5 + ++i; printf("i=%d, j=%d\n", i, j); | i=6, j=11 |
| What is the primary purpose of the else clause? | To execute code when the if condition is false. |
| int score = 85; if (score > 90) printf("You got an A!\n"); printf("Congratulations!\n"); | Congratulations! |
| A switch statement can be used to check if a floating-point number is within a certain range. (T/F) | False |
| A switch statement can only evaluate integer types (like int and char) and can only check for equality against constant case values, not ranges. (T/F) | True |
| The keyword that causes execution to jump out of a switch block is _______. | break |
| What is the output of the following code snippet? int x = 2; switch (x) { case 1: printf("A"); case 2: printf("B"); case 3: printf("C"); break; default: printf("D"); } printf("\n"); | BC |
| If no case in a switch statement matches the expression's value and there is no default case: | Execution continues at the statement immediately following the switch block. |
| A series of if, _________ , and else statements is often called an if-else cascade. | else if |
| Using a char variable in a switch statement is valid because characters are secretly integer types in C. (T/F) | True |
| What will this code print? int temp = 75; if (temp > 80) { printf("Hot"); } else if (temp > 60) { printf("Warm"); } else { printf("Cool"); } printf("\n"); | Warm |
| The default case in a switch statement is: | Optional and can be anywhere |
| The expression that controls a switch statement in C must evaluate to which type of value? | An integer value |
| It is valid to use a char variable as the controlling expression in a switch statement, and char literals for case labels (T/F) | True |
| Which loop construct is guaranteed to execute its body at least one time? | do-while |
| What are the three expressions inside the parentheses of a for loop? | initialization, the condition, and the post-iteration (increment/decrement) expression. |
| The body of a while loop will always execute at least once. (T/F) | False |
| What is the output of the following code snippet? int i = 5; do { i++; } while (i < 5); printf("%d\n", i); | 6 |
| How do you write an infinite loop using a for statement? | for (;;) |
| What is the primary issue with the following while loop that intends to count from 0 to 9? int i = 0; while (i < 10) { printf("%d\n", i); } | The loop is infinite because the control variable i is never updated. |
| How many times will the following loop print "Hello"? for (int i = 10; i > 0; i -= 3) { printf("Hello\n"); } | 4 |
| When is a for loop generally a better choice than a while loop? | When the number of iterations is known before the loop starts. |
| What is the final value of count after this loop finishes? int count = 0; for (int i = 0; i < 10; i++) { count++; } | 10 |
| What is the output of the following code? int i = 0 int j = 5; while (i < j) { printf("%d ", i * j); i++; j--; } printf("\n"); | 0 4 6 |
| In C, the "pass by value" mechanism means that: | The function receives a copy of the argument's value, and any changes are made to that local copy. |
| A function ___________ is a declaration that tells the compiler about a function's name, return type, and parameters before the function is actually defined. | prototype |
| If a function has a return type of void, it means the function returns a value of 0 by default. (T/F) | False |
| What is the output of the following program? #include <stdio.h> void double_value(int y) { y *= 2; } int main(void) { int y = 5; double_value(y); printf("%d\n", y); return 0; } | 5 |
| What is the key difference between a function's "parameter" and its "argument"? | A parameter is the local variable in the function definition, while an argument is the actual value passed in the function call. |
| In modern C (C99 and later), what kind of error does this cause? #include <stdio.h> int main(void) { int result = add(5, 10); // Error here! printf("Result: %d\n", result); return 0; } int add(int a, int b) { return a + b; } | Implicit Declaration Error: The compiler will stop because it has no information about the function's return type or parameters. |
| To indicate that a function takes no arguments, you should use the keyword ______ in its parameter list. | void |
| The prototype void print_message(); is functionally identical to void print_message(void); in all versions of C. (T/F) | False |
| Where is the function prototype for printf() typically found? | In the <stdio.h> header file. |
| What is the primary benefit of using functions in C programming? | To organize code into reusable blocks and improve readability and debugging. |
| Which of the following best describes the "pass-by-value" mechanism in C? | The function receives a copy of the argument's value, operating independently of the original variable. |
| What does a function prototype primarily communicate to the C compiler? | The return type and the types of its parameters. |
| If a function is declared with a void return type, what does this signify? | The function does not return any value to the caller. |
| What is the significance of "passing by reference"? | It allows a function to receive a direct pointer to the original variable, enabling modification. |
| Function prototypes exist primarily to inform the compiler about a function before its full definition, helping to prevent "unknown function call errors". (T/F) | True |
| A pointer in C is a variable that: | Holds an address of another variable |
| Which operator is used to obtain the address of a variable? | & |
| What does the %p format specifier do in printf()? | Prints a pointer (address) |
| What is the output of the following code snippet? int i = 10; int *p = &i; *p = 20; printf("%d", i); | 20 |
| The dereference operator is: | * |
| What is the correct way to declare a pointer to an integer? | int *p; |
| If p = NULL;, then: | p doesn't point to any valid memory |
| What will happen if you try to dereference a NULL pointer? | It crashes or causes undefined behaviour |
| In the statement int *p, q;, which variables are pointers? | Only p |
| When passing a pointer to a function: | The function gets a copy of the pointer |
| The operator used to find the address of a variable is ___. | & |
| The operator used to access the value stored at a pointer's address is ___. | * |
| The special value used to indicate that a pointer does not point anywhere is ______. | NULL |
| The size of a pointer can be determined using the ________ operator. | sizeof |
| The expression sizeof *p returns the size of the type that the pointer p ___________. | points to |
| In C, the first element of an array declared as int a[10]; is accessed using the index a[1]. (T/F) | False |
| If you declare int arr[10]; in main() and pass it to a function void func(int arr[]), the expression sizeof(arr) inside func() will return the total size of the array in bytes (T/F). | False |
| How do you declare an array named scores that can hold 10 integers? | int scores[10]; |
| What is the index of the last element in an array declared as float data[25];? | 24 |
| Given the declaration int a[5] = {10, 20};, what is the value of a[3]? | 0 |
| If you have an array int arr[10];, what does the expression arr evaluate to? | A pointer to the first element, equivalent to &arr[0]. |
| Given int arr[] = {5, 10, 15, 20};, which expression is equivalent to arr[2]? "*arr + 2", "arr + 2", "&arr +2", "*(arr + 2)" | *(arr + 2) |
| What is the primary danger of accessing an array out of bounds, such as a[10] in an array int a[10];? | It results in undefined behaviour, which could include corrupting other data, reading garbage values, or crashing the program. |
| Which function prototype cannot be used to accept an array int scores[20]; as an argument? "void process(int s[]);", "void process(int s[20]);", "void process(int *s);", "void process(int s)" | void process(int s); |
| What is the correct way to declare a 2D array (matrix) that has 5 rows and 10 columns of type double? | double matrix[5][10]; |
| A C string is simply a char array that must end with a special null terminator character, which is represented as '\0'. (T/F) | True |
| The strlen("hello") function will return a value of 6, because it includes the null terminator in its count. (T/F) | False |
| Given the declaration char s[20] = "Hi";, what is the result of strlen(s) and sizeof(s)? | strlen is 2, sizeof is 20 |
| Which <string.h> function is used to compare two strings to see if they are alphabetically equal? | strcmp() |
| If strcmp(s1, s2) returns a value of 0, what does this mean? | s1 and s2 are equal. |
| Consider this code: char s[5] = "Hi "; strcat(s, "there!"); What is the most likely outcome? | The program will write data past the end of the array s, causing a buffer overflow and undefined behaviour. |
| What is the key difference between strcpy(dest, src) and strncpy(dest, src, n)? | strncpy copies at most n characters, which helps prevent buffer overflows. |
| Why is the gets() function considered extremely dangerous and bad practice? | It has no way to limit the number of characters it reads, leading to easy buffer overflows. |
| After a successful call to fgets(s, 10, stdin) where the user types "Hello" and presses Enter, what will be stored in the string s? | "Hello\n" |
| What is the difference between strchr(s, 'c') and strstr(s, "c")? | strchr finds the first occurrence of the character 'c', while strstr finds the first occurrence of the substring "c". |
| A struct in C allows you to group variables of different data types into a single, user-defined type. (T/F) | True |
| When you pass a struct variable to a function by value, the function operates on a copy of the struct, and any changes made inside the function will not affect the original struct in the caller. (T/F) | True |
| Which syntax correctly defines a struct type? struct Student(char name[50]; int id;); struct Student { char name[50]; int id; }; Student struct { char name[50]; int id; }; struct { char name[50]; int id; } Student; | struct Student { char name[50]; int id; }; |
| Given the declaration struct Student s;, how do you access its id member? | s.id |
| Given struct Student *p; (where p points to a valid Student struct), how do you access its id member? | p->id |
| The expression p->id (where p is a struct pointer) is syntactic sugar for which other expression? | (*p).id |
| What is the purpose of using typedef with a struct, as in typedef struct student Student;? | It creates an alias (a new name) for the struct type, so you can just type Student s; instead of struct student s;. |
| What is the most common and efficient way to pass a large struct to a function, especially if the function only needs to read (not modify) its data? | Pass a pointer to the struct (e.g., void func(struct student *s);). |
| Given the declaration struct student roster[30];, how would you access the id of the first student in the array? | roster[0].id |
| Assuming the definition struct student { int id; double gpa; };, which of the following correctly initializes a struct student variable? "struct student s = {123, 95.5};", "struct student s = [123, 95.5];", "stuct student s = (123, 95.5);" | struct student s = {123, 95.5}; |
| The fopen() function returns NULL if it successfully opens the requested file. (T/F) | False |
| For every single call to malloc() that returns a non-NULL pointer, there should be a corresponding call to free() to prevent a memory leak. (T/F) | True |
| What fopen() mode is used to open a file for *reading only*? | "r" |
| What fopen() mode will create a file if it doesn't exist, or overwrite it if it does exist, for writing? | "w" |
| What function is used to write formatted output to a file, similar to printf? | fprintf() |
| What is the purpose of the malloc() function? | To allocate a block of memory of a specified size from the heap, which must be manually freed. |
| Which code snippet correctly allocates memory for an array of 50 integers? | int *p = malloc(50 * sizeof(int)); |
| What function is used to release memory that was previously allocated with malloc() or calloc()? | free() |
| What is the safest function to read a line of text (a string) from an open file handle fp? "fgetc(fp);", "fgets(buf, size, fp);", "gets(buf);", "fscanf(fp, "%s", buf);" | fgets(buf, size, fp); |
| What happens if you forget to call free() on memory allocated with malloc()? | A "memory leak" occurs, where the memory remains allocated but unusable for the life of the program. |