C BASICS Flashcards

1
Q

What are C filez

A

C files are source code for your program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How are C files executed

A

They are compiled with a compiler (gcc for instance) to create an executable file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Variables always have a type

A

Example

int i;
char c;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are arrays declared

A

type var_name[num_of_items]

eg.
// array of 32 contiguous int
int my_array[32];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s a structure?

A

A complex data type declaration that
defines a physically grouped list of
variables to be placed under one name
in a block of memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Declaration and creation of structure

A

struct structure_name {
type name;

};
struct structure_name var_name;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are Functions

A

Functions:


Sequence of program instructions that perform a specific task,
packaged as a unit

May take arguments as input information

Compute something

May return a result

Functions can call functions
Parameters and return values must have a type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Functions syntax

A

return_type function_name(type param1, type2 param2, … )
[ block ]

example
int my_func(int a, char b)
[ block ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

All C program starts from where?

A

The main function
Aka the entry point
From the main function, you can call other functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens when main returns

A

The program stops

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s are blocks in C

A

Blocks or code blocks are sections of code which are grouped together. Blocks
consist of one or more declarations and statements.
Blocks are delimited by curly braces { and }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a char in C

A

‘letter’ (single quotes)
The value of a character is its ASCII code (man ascii)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are strings in C

A

“string” (double quotes)
Evaluates to the address in memory of the first character of the string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Arithmetic operators in C

A

+ addition, - subtraction, * multiplication, / division, % modulo (integer remainder)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does ++var, var– do?

A

Increment and decrement
++var // Increment var by 1, value of the expression is the value of var after the increment
var– // Decrements var by 1, value of the expression is the value of var before the decrement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Logical operators

A

|| OR, && AND, ! NOT

expression1 || expression2 - if one of the 2 expressions is true, then the whole
expression is true
expression1 && expression2 - if one of the 2 expressions is false, then the whole
expression is false
!expression - if the expression is false, then the whole expression is true. If the
expression is true, then the whole expression is false.
The value of the whole expression is 0 if false, something else if true

17
Q

Who created the C programming language

A

Dennis MacAlistair Ritchie

18
Q

Intrinsic data types

How many bytes is a ‘char’ ‘int’ ‘float’ ‘double’ ?

A

Typically
‘char’ - 1 byte
‘int’ - 4 byte
‘float’ - 4 byte
‘double’ (extended precision float) - 8 byte

19
Q

sizeof() operator

A

Can be used to determine the amount of size any intrinsic data type, union or struct takes in bytes.

20
Q

Type casting

A

float f;
int i = 10;
f = (float) i; // assigned 10.0 to f

f = 3.14;
i = (int) f; // assigned 3 to i