Getting Started Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Four Important aspects of any language:

A
  1. Way it stores data
  2. Way it operates upon it.
  3. how it accomplishes input and output.
  4. how it lets you control the sequence of execution of instructions in a program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why is C used in some parts of Operating systems?

A

Speed of execution.

Device drivers are written in C.

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

Steps of learning C:

A
  1. Alphabets; Digits; Special Symbols.
  2. Constants; Variables; Keywords
  3. Instructions
  4. Program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The C character Set

A

All alphabets, Capital and small.
All digits 0-9
Special Symbols o keyboard [31].
[ ~ is but ` is not valid]

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

Constant, Variable and Keywords:

A

These formed by the combination of the C character set.
Constants: Entity with a fixed value.
Variables; Entity with changing values.

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

Variable names theory:

A

The memory locations are given names and since the value stored in these memory keeps changing hence called variable names.
This allows us to retrieve and use the value stored in the memory location.

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

Types of C constant:

A
  1. Primary
    Integer constant; Real Constant; Character Const.
  2. Secondary constants
    Array; Structure; Pointer; Union; Enum,..etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Rules Of Integer Constant:

A
  1. Must have at least 1 digit.
  2. Must not have a decimal point.
  3. Can be +ve or -ve.
  4. No sign implies +ve.
  5. No commas and blanks allowed.
  6. Range: -32768 to 32767 [ depends on Compiler, this
    is for a 16-bit compiler.]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Rules for constructing Real Constants:

A
aka Floating Point Constants.
expressed in 2 forms:
1. Fractional Form:
   a. at least 1 digit.
   b. Decimal point Must.
   c. Can be +ve or -ve, default +ve
   d. No commas, blanks allowed.
  1. Exponential Form: [For too small or too big value]
    a. Has mantissa and exponent[separated by e]
    b. Mantissa can be +ve or -ve, Default +ve.
    c. Exponent must have at least 1 digit again maybe +ve or -ve. Dafault is +ve.
    d. Range: -3.4e38 to 3.4e38
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Rules for Constructing Character Constants:

A

Character constant has max length of 1 character.

Enclosed in inverted commas, both single inverted, towards left.
like : ‘A’
‘1’
‘@’

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

In a language, the type of variables supported depends on ?

A

the type of constant supported.

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

Rules for constructing Variable Names:

A
  1. length 31 (some compilers: 247)
  2. First char must be alphabet or underscore
  3. No commas or blanks are allowed.
  4. ONly special symbol allowed is an underscore.

These rules apply for all types of primary and secondary variables.

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

To differentiate between variables what is done?

A

Type declaration statements.
int varname;
float varname;
char varname;

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

C keywords:

A

keywords cant be used as var names.
they are already explained to the compiler.
AKA reserved words
There are 32.
auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while

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

Compiler Specific keywords:

A

ANSI said they should be preceded by 2 underscores.

like __near, __far, __asm

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

C program

how do instructions or statements make them?

A

Each instruction is written as a separate statement.
Therefore, a C program compromises of a series of statements.
They must appear in the order in which we expect them to execute.
To increase readability u can insert blacnk spaces btw words but not btw varnames, constant, keyword.
Statements are entered in small case letters.

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

Statement terminator:

A

;

Every statement ends with a ;

18
Q

Comments:

A

Comment enclosed in /* */
can be anywhere, even btw the statement.
To explain code or provide information.

Compiler Completely Ignores it.

19
Q

Can comments be multiline?

A

Yes

20
Q

Can comments be nested?

A

NO

21
Q

C is also called as free form cuz:

A

No specific rules for position at which a statement should be written.

22
Q

Declare a variable:

and whats initialisation?

A
int n;
int or float or char
Declare before using.
Assigning value to it is intialising.
int i = 10;   /* declared and initialised */
23
Q

function printf()

A

printf( “”,);

format string may contains format specifiers :
%f to print real value
%d for int
%c for char
%s - char.
%p - address. 
%u - unsigned Integer.

list of variables can contain Expressions.

24
Q

NewLine

A

Takes cursor to next line.
\n
One of the Escape Sequences.

25
Q

Compilation and Execution:

A

To type your C program you need an EDITOR.
once written it is necessary to convert it to machine lang(0s, 1s) so machine can execute it. Compiler performs this conversion.

Integrated Development Environment: Provides editor and compiler.

26
Q

scanf() function:

A

scanf(“%d%f%c”,&int,&real,&char);

ampersand [&] : Address of operator.
&int : We are telling at which memory location should it store the value supplied by user.
User must use blank,tab or newline(enterkey) to separate the inputs.
27
Q

Types of instructions:

A
  1. Type Declaration
  2. Arithmetic
  3. Control Instruction
28
Q

Is it valid?

int a = b = c = d = 10 ;

order of assigning

A

Its invalid as u are assigning b to a before defining it.
but
int a,b,c,d; a = b=c = 10; will work.
float a = 1.5, b = a; is fine but
float b = a+ 1.1, a = 1.5; is not.
as we are trying to use before defining it.

29
Q

Operands:

A

Variables and constants on RHS of = [assignment operator], as these are operated by the arithmetic operators [+,-,*,/].

30
Q

Arithmetic Instructions :

way of assignment

A

Value on the right of = is assigned to left.
RHS is evaluated using constants and numerical values stored in variable names. This value is assigned on the LHS.
One variable is allowed on LHS

31
Q

Types Of Arithmetic Instructions:

A
  1. Just Integer constants and variables.
  2. Real mode
  3. Mixed mode [real and integer operands]
32
Q

% operator:

A

Modulus operator returns remainder, not applied on floats.
Sign of numerator is assigned to the remainder.
5% -2 = 1
-5 % 2 = -1

33
Q

Arithmetic Instruction on char:

A
1. To store constants in char variable.
char  a; a = 'F';
a will store F's ASCII value i.e 70.
int z; z = a + 'G';
Addition is performed on ASCII values of chars. z = 70+71
34
Q

The one missed operator in C?

A
Exponentian.
but we can use:
#include 
main()
{
/* 3 raise to 2 */
print("%d",pow(3,2) );
}
35
Q

Integer to float conversion:

A

Implicit:

Operation on real and integer yields a real, the integer is converted to real and the operation is performed.

36
Q

float a,b,c ;
int s;
s = a * b * c /100 + 32/4 - 3 * 1.1;

discuss conversions:

A

Type Conversion In Assignments.
during evaluation in RHS everything is promoted to real if it’s not but since s is an int it can’t store real so evaluated value gets demoted to integer and is stored in s.

37
Q

Hierarchy of Operations:

A
  • , / , % > + , - > =
38
Q

Associativity of Operators:

A

Its of 2 types:
1. Right to left [ = ]
2. Left to right [ +,/,*]
Used to break tie when same priority operators come together, like / , * .
In left to right : Left operand must be unambiguous, not involved in any sub expression. Then its performed early.

39
Q

a = 3/2*5

How will compiler proceed?

A

/,* have L to R associativity.

but / has its left operand unambiguous hence it is performed earlier then *.

40
Q

Control Instructions:

A
  1. Sequence Control.
  2. Selection or Decision Control.
  3. Repetition or Loop control Instruction.
  4. Case Control.
    These instructions enable us to specify in which order must instructions be executed.
    Determines ‘ Flow Of Control’.