C Flashcards
How do you start all c programs?
#include int main(void)
What is a computer?
Any device with the following things:
INPUT/OUTPUT to communicate with the outside world
MEMORY to record data and programs
CPU to carry out instructions.
What is an embedded computer?
One designed to do only one thing, like in a ATM
What is the clock in a computer?
Clock – this is a high frequency square wave which is an alternating pulse of zeros and ones. These usually operate at GHz frequencies for desktop and laptops, and at MHz frequencies for embedded computers.
The clock is required by all units inside a computer to ensure that all their operations are synchronised
What is a computer bus?
Bus – a bus is a collection of wires which connects any two components, such
as the memory and the CPU. If a bus mainly carries data, it is the data bus and
if it carries memory addresses, then it is the address bus.
What is a bit?
The fundamental unit of information in computing is a bit.
A bit indicates the presence of a high or low voltage on a bus. High-voltage values are given the bit value of ‘1’, low-voltage values have a bit value of ‘0’.
How are bytes arranged?
Contain 8 bits.
128 on the left (bit 7) and 1 on the right (bit 0)
How are negative numbers represented with bytes?
Declare and use a sign variable. Bit 7 is worth -128
How much in a kilobyte?
2^10 bytes. 2^20 in a megabyte, 2^30 in a gigabyte and so on.
How are hexadecimal values used in c?
int q = 0x102;
begin each number with 0x
printf and scanf both use the format “%x” to enter or display hexadecimal values
What is a memory location?
A unique location which is the address and o 1 byte of data.
What is a word?
A group of bytes put together in memory when 1 isn’t big enough. Usually in groups of 2,4 8…
What does & do with memory?
The ‘&;’ operator is the “address-of” operator. This takes any variable and returns the memory address at which that variable is stored.
What does * do with memory?
The ‘*’ operator is the “contents-of” operator. This takes a memory address and returns the contents at that memory location.
What is the form of a text file?
A text file stores all of the data as “ASCII” characters and then stores the binary representation of each ASCII character.
The number 100000 would take up 6 places.
What is portability?
This means that the data within a file is readable on all kinds of computers and operating systems.
Which of text or binary files are human readable?
text
Which is larger when storing the same amount of data?
text
What is one of the disadvantages of binary files?
Binary files are (in general) non-portable – binary files created using C under one operating system can’t be automatically read on another operating system, unless special procedures are used.
Binary files can only be made portable if we use an internationally-defined standard file format.
Give some examples of text and binary files?
Examples of text files: .c files, .txt files, .html files, emails.
Examples of binary files - .mp3 files, .gif files, .wav files, .exe files.
what are the four data types?
int, float, char and double
When printing values in printf what are the letters needed to place them?
%d for int
%f for float
%c for character
%e for double
What must you not do with comments?
nest them
What does \t mean in a printf?
A tab
A small gap in the line
What makes a good variable name?
Must start with _ or character.
Can have uppercase lowercase or numbers
How do you do comments?
/* */
how would you change the number of decimal places displayed in printf?
for a double using %.2e would give it to 2 decimal places
What is the casting of variables?
Changing their data type.
If you wanted to perform floating point division with integers
float answer
answer=(float)value1/(float)value2;
What is a debugger?
A program within a compiler that pauses a program and analyses what’s going on.
What does ++ do?
Increment. Add 1 to the value. Whether it is in front of a variable or after it matters.
What is the modulus operator?
answer=20%3;
Would return a value of 2 as it gives the remainder when 20 is divided by 3.
What does
time*=hours do?
time=time*hours
What needs to happen for you to use more complex maths functions?
include header
How do you determine the square root of a number
sqrt(x)
math header needed
symbol for AND
&&
Symbol for OR
||
Symbol for NOT
!
Symbol for Exclusive-OR
How are powers evaluated?
pow(x,3) gives xxx
don’t use ^
What are the evaluaters used with scanf to enter different variables?
%lf or %le for doubles
%f for float
%d for integer
How does #define work?
Used to make small functions or values #define square(x) x*x #define absolute_zero -273
What does != mean?
Not equal to