CS 315 Quiz 1

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

How many bits in a byte? a. 1 b. 4 c. 9 d. 8

(*)d. 8

True or False, would (1.0/3 + 1/3.0 + 1.0/3.0) == 1 return true (a non-zero value in C)? (a) true (b) false

(b) false (*)

When integral types are mixed together in arithmetic expressions, how does the compiler deal with different widths present? (Ex. ('b' + 5)) A. Promotes the smaller type to be the same size as the larger type B. Demotes the larger type to be the same size as the smaller type C. Find a type with a size in the midpoint of the two types and convert each type by promoting the smaller type and demoting the larger type

A. Promotes the smaller type to be the same size as the larger type (*) Explanation: Promotions are determined at compile time based purely on the types of the values in the expressions and do not lose information as they always convert from a type to compatible, larger type to avoid losing information.

What is the correct output of this code? #include void main() { char s[] = "C++"; printf("%s ",s); s++; printf("%s",s); } A : C++ C++ B : C++ ++ C : ++ ++ D : Compile error

Answer : D Explanation : 's' refers to a constant address and cannot be incremented.

What type of value does sizeof return? A. Short B. Char C. Unsigned int D. Long

Answer: C Unsigned Int

vi, vim, emacs, and ne are all console-based editors True False

Answer: True

Using Internet Sharing, where does the Raspberry Pi get it's IP address from: a) The WiFi router b) Rasbian Linux c) The host OS on your laptop d) None of the Above

Answer: c) The host OS on your laptop Explanation: Internet Sharing found in MacOS, Windows, and Linux assigns an IP address to the connected Raspberry Pi so it can connect to the internet. Essentially, your laptop OS is acting like a router for your Raspberry Pi.

We know that int a, b, c, *d=&c, and which of the following statement can be used to ask the value of variable a, b and c from the user? A. scanf("%d%d%d", &a, &b, d) B. scanf("%d%d%d", a, b, d); C. scanf("%d%d%d", &a, &b, &d); D. scanf("%d%d%d", a, b,*d);

A. scanf("%d%d%d", &a, &b, d) (*)

Consider this code block: char c = '4'; int y; What is is proper conversion from '4' (char c) to 4 (y = 4)? A) y = (int) (c + '0'); B) y = int (c + '0'); C) y = (int) (c - '0'); D) y = int (c - '0');

C) y = (int) (c - '0'); (*)

Assuming that ptr points to a primitive data type, what is the following equivalent to in regular arithmetic? ptr + i a) (ptr + (i * sizeof(*ptr))) b) (ptr + (i * sizeof(ptr))) c) (ptr + 4) d) (ptr + (i + sizeof(ptr)))

Correct Answer: a Explanation: Incrementing a pointer by a number i is equivalent to incrementing the pointer in memory by x bytes, where x is the size of of the data type that ptr points to, times i.

Char, arrays, pointers, structs, bool, and double are all examples of native data types in C. True False

False (*)

The size of a struct in C is always exactly the number of bytes needed to store all the members of the struct. True False

False (*)

Topic: Raspberry Pi True/False? If a C program executes on your laptop's host OS and processor, simply sharing the executable file will allow you to run the code on your pi. A.) True, but only for machines that have the same OS B.) False

False (*)

True or False: To view the Raspberry Pi configuration menu in your terminal window, type the command $ sudo rpi-config into the command line of the Raspberry Pi. True False

False (*)

Signed is 0 to 255, unsigned is -128 to 127. True False

False (*) Explanation: If char's have 8 bits, unsigned char variables have values between 0 and 255. if char's have 8 bits, signed char variables have values from -128 and 127.

True or false: By declaring a pointer you allocate space for the pointer and the pointee. True False

False (*) Explanation: When you declare a pointer, space is allocated for the pointer but not for the pointee, which must also be declared. For the relationship between a pointer and a pointee to work, you must remember three things: (1) the pointer has to be declared and allocated (2) the pointee has to be declared and allocated (3) the pointer has to be initialized so it points to the pointee

The computer processor can natively execute which of the following? C source code Machine code Java code Python code

Machine Code Explanation: Computer processors only understand how to execute binary instructions that conform to the instruction set architecture of the processor (e.g., ARMv7, Intel x86, etc.). Therefore, B is true.

What is the correct output #include <stdio.h> int main() { float c = 5.0; printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32); return 0; } The temperature in Fahrenheit is 41.00 The temperature in Fahrenheit is 23.00 The temperature in Fahrenheit is 37.00 Compiler error

The temperature in Fahrenheit is 37.00 (*) Explanation: Since 9 and 5 are integers, integer arithmetic happens in subexpression (9/5) and we get 1 as its value. To fix the above program, you can use 9.0 instead of 9 or 5.0 instead of 5 so that floating-point arithmetic happens.

In C, the programmer is responsible for deallocated all unused heap allocated memory with the free() function. True False

True

True/False: Signed int and unsigned int values can represent the same number of unique values. True False

True

The serial line connection allows you to connect to a Raspberry Pi without a network connection. True False

True (*) False Explanation: The serial connection is a way to directly interact with the Raspbian Linux console using a serial terminal program. No network connection like Ethernet or WiFi is needed. This is how we can configure Raspbian without a separate keyboard and mouse. You would still need to set up network configurations if you want to have internet access.

Topic: C operators Consider the following program, what is the output? #include <stdio.h> int main(int argc, char **argv) { int a = 0, b = 0, c = 0; int x = a++ || ++b || --c; printf("a+b+c=%d x=%d\n", a + b + c, x); return 0; } a+b+c=0 x=1 a+b+c=1 x=1 a+b+c=2 x=1 a+b+c=1 x=0

a+b+c=2 x=1 (*) Explanation: a++ increments the value of a and return the original value, while ++b increment the value of b and return the incremented value. On the other hand, latter expressions after a true in OR will be skipped. So, a is 1, b is 1, c is still 0, and x is 1, which means true. Therefore, the output is a+b+c = 2, x = 1.

What is the output of the following program? #include <stdio.h> void func1(int arr[]) { printf("%d\n", sizeof(arr)/sizeof(int)); } int main(int argc, char **argv) { int arr[] = {1, 2, 3, 4, 5, 6}; printf("%d ", sizeof(arr)/sizeof(int)); func1(arr); return 0; } a. 6 6 b. 6 1 c. 1 1 d. 1 6

b. 6 1 (*)

What type of processor do the Raspberry Pis we use have? a) x86 b) x64 c) arm d) leg

c) arm *

#include <stdio.h> int main(int argc, char **argv) { int b1 = 7, b2 = 11; printf("b1 ^ b2 = %d\n", b1^b2); return 0; } What it the output of the above code? a) b1 ^ b2 = 15 b) b1 ^ b2 = 11 c) b1 ^ b2 = 18 d) b1 ^ b2 = 12

d) b1 ^ b2 = 12 (*)

What is the default floating point type in c? float double int long double

double

int i = 42; int j; j = (i++ + 10); j = (++i + 10); what are the values of i and j after executing this code snippet? a. i = 43 / j = 53 b. i = 44 / j = 54 c. i = 42 / j = 53 d. i = 42 / j = 52

explaination: the correct answer is b because i is incremented, but i++ is a post variant meaning that j represents i before the change. on the second assignment, i is incremented with a pre variant meaning that j represents i after the change.


Ensembles d'études connexes

Brunner & Suddarth's textbook of medical-surgical Nursing (13th) ch23

View Set

Fire Inspector Test Set ch 12-16

View Set

Chapter 33 & 34 - Animal Diversity and Invertebrates

View Set

Yo, Tu, Ella/el/usted, Nosotras/nosotros, Vosotras/Vosotros, Ellas/ellos/ustedes

View Set