Briefly define source code and machine code.
What is a compiler?
What is the difference between a GUI and a CLI.
Attached example of a CLI
What is the significance of the $ sign in the terminal window?
It means “type commands here”.
What is the syntax in C for displaying text in the console and what does each part mean? (the console is the terminal window or te cli window where the program outputs results)
printf("some text\n");
printf - the command to print text. “f” is for “formatted”. It allows you to print output with some formatting included.() curley braces are for specifying what the parameters will be for the function. In this case the printf function expects some input like text to print." - Every time you write text you need to quote it. like "hello, world"\n - Means formatting for a newline. the \ is an “escape” character, which means that the next part of text is not part of the string of words.; - This is the end of the statement.what does #include <stdio.h> do in C?
stdio.h is Standard Library that provides input and output capabilities for C programs.printf function avaialble for use in your code.Why do you need to recompile code?
Whenever you change your source code you need to recreate or update the binary file. This means “recompiling” the code.
Define return value.
Its a value you get back from a function that you can use/read. Its the output value of a function.
What is the code to ask the user for an input with C?
string answer = get_string("What's your name? ");
What is the purpose of the = sign in C?
What type is used for a variable that is assigned to words?
stringe.g. string MyName = "cilliers";
What is the purpose of assigning a “type” to a variable?
You are informing the computer what “type” of data is going to be assigned to the variable.
In C how do you combine a value from a variable into a string?
%s value is used as a placeholder.printf("hello, %s",anwers);What is the command for creating a new file named “hello” in C?
$ code hello.c
Exercise - In VS Code:
1. Create a new C file called “helloWorld”
2. Write a program that will print “hello world” to the command line internface.
Write the code to do an if else which prints out if X is larger than Y or if its the same.
What does = mean in C and what do you do when you want to copare if some values are equal?
The = sign is an assignment character. It assignes the value on the variable on the left.
If you want to compare values you need to write the coparitor == which evaluates if the value on the left is the same as the value on the right.
What is the difference in using " or ' in C?
When dealing with strings or multiple lines of characters you need to use " when deliberately dealing with single characters you need to use '. Single characters are “char” types as opposed to “string” types.
It is meant to ensure that the computer knows you are working with a char.
How do you write an OR condition in C?
||
e.g.
if (x = 2 || x =1){
//do something
}What does this code do and how can you simplify it?
int counter = 5; counter = counter+1;
First line initializes a variable of type int named counter and assignes a value of 5.
Second line adds 1 to the counter. Assignment says that the value on the right is assigned to the variable on the left. Meaning counter+1 is equal to 6 and is assigned to counter on the left. Counter is now 6.
To simpify it C allows you to write counter+=1;
Or even, in the case of integers where you just want to increment by 1 you can write counter++;
How would you write a “while loop” in C to loop 3 times and print a string? How would you then simplify that?
int counter = 3;
while (counter > 0)
{
printf("mystring /n");
counter--;
}
**simplification**
for(int x = 0; x <3; x++)
{
printf("mystring /n");
}Write a “while loop” that wil continue forever.
while (true)
{
do the code;
}What is the cli command to display files in a folder and what is special about the * files?
ls
Typing ls in CLI wil list all the files in a folder.
Files with the * extension are executable files. a.k.a. programs. when you type ./thefilesname the computer wil execute the program.
How do you rename a file in the CLI in Linux?
mv nameoffile newnameoffile
mv means move and allows to rename and move