110 - Software Development Flashcards
What is the print function in C?
Printf()
How to start a program?
- Decompose the problem into a small number of steps
2. Then again into subsets until you can start to program
What does this do?
for (i=0; i<10; i++)
{
print(“Hi!\n”);
}
It is a for loop that allocated the value of “0” to the variable called “i”. Then for states “for as long as i is less than 10, print “Hi” then add 1 each time
What does “%d” mean?
Print an integer
What does “scanf()” do?
It gets the user input
Always remember to do what?
Add meaningful comments to clarify what your code is trying to achieve
What does Camelcase look like?
camelCase
What is an Array?
Arrays provide a way for storing multiple instances of the same data type
What index is the 2nd place in the array and why?
Index 1 because the indexes start at index 0
What do functions do?
Create reusable units of code to help avoid repetition by factoring our common elements
What does “rand()” do?
It generates a random number.
Function definitions have what form?
Direct-declarator (parameter-type-list)
Functions DO NOT return what?
- A union
- An arithmetic type
- A function
- A structure
- An array
- A pointer
- A void
(Pick two)
A function and an array
In C, functions may have side effects (e.g. printing) what is not always needed to prevent this?
The return value
What does “void” mean?
It means that nothing is returned
What do you need at the beginning of every C program?
Int main()
What does it mean when you say x = y?
You’re copying the contents of “y” into “x”
What is a pointer?
A pointer is a variable that contains the address of a variable
What does “int *p = &x; mean if:
int x = 65; (index 3)
int y = 32; (index 1)
It is pointing to the place in member where int x is. In this case , the answer is index 3
What does p = &x; do?
It puts the address of box x into p
What does *p = 8; do?
Puts the value 8 into the box pointed to by p
What does “printf(“%d\n”, marks[0] if
7 | marks[0] = 55;
8 | marks[1] = 65;
9 | marks[2] = 70;
Print the integer that in is “marks[0]”
What’s the difference between;
printf(“%d\n”, marks);
and
printf(“%d\n”, *marks);
The first statement prints out the integer that is located in “marks” and the second statement prints out the integer that “marks” is pointing to
Why is a “&” needed before the variables when using “scanf”?
It needs to modify the variable
What is a string?
It is text or a sequence of characters
How many spaces in memeber does char s[] = “hello”; and why?
It’s 6 elements long because it also null byte “\0”. This tells the computer when to stop
How do you calculate the length of a string?
Using the “strlen()” function. Start at the beginning and check to see if you’ve reached the null byte