C programming 2 Flashcards
What is an Lvalue?
The assignment operator requires an Lvalue as it’s left operand ,a variable for example.
An Lvalue is an object stored in computer memory not a constant or a result of computation.
What are some tips to avoid undefined behavior?
Avoiding writing expressions that access the value of a variable and also modify it in same expression.
Some compilers may produce a warning.
It’s also a good practice to avoid using assignment operators in subexpressions , and using a series of separate assignments instead.
Name the operators that modify their operands.
Assignment operators, decrement and increment are the only operators that modify their operands.
And care must be taken to not write an Expression that depend on a particular order of evaluation.
What is fetching in C programming and how does it function?
Fetching a variable means to retrieve the value of the variable from memory, a later change to the variable won’t affect fetched variable which is typically stored in register inside the CPU.
What is undefined behavior in C ?
When a program ventures into the realm of undefined behavior all bets are off , it may behave differently when compiled with different compilers, or might not compile at all , or may compile but not run , or runs but then crashes , behave erratically or produce meaningless results.
What is an Expression statement in C ?
C has an unusual rule that any expression can be used as a statement , It’s done by turning an expression into a statement by adding a semicolon at the end.
Which makes sense only if it has side effects.
How do C compilers deal with expression statements that do nothing?
Some of them may show a warning of “statement with no effect”.
How to raise a number to a power “exponentiation” in C language?
It’s best done by repeated multiplication ,for noninteger power use pow function.
How to apply the % operator to a floating-point operand ?
The % operand requires integer operands ,try the fmod function instead.
In C Standard ,What is the guaranteed result of : (a / b )* b + (a%b) ?
a
Why does C provide the ++ and – operators, are they faster or just more convenient?
Historically C inherited it from B language , Thompson apparently created these operators because his B compiler could generate a more compact translation for ++i than for i = i + 1.
But it’s continued popularity is due to it’s brevity. And convenience.
Do ++ and – work with floats ?
Yes.
When using postfix ++ or – when do the increment or decrement be performed?
Unfortunately it’s difficult to answer , C standard introduce the concept of “sequence point” and says that “updating the stores value of the operand shall occur between the previous and next sequence point”.
What are some kinds of sequence points in C? explain them briefly and give situations that impose them .
One kind is the end of an expression statement , by the end of it all increments and decrements within the statement must have been performed (after the previous sequence point and before the next one), the next statement can’t begin until this condition has been met.
Certain operators like logical and , logical or , conditional and comma also impose sequence points.
Also function calls does , because it’s arguments must be evaluated before the function is called ( they may contain an increment or decrement)
What’s meant by that statements like ( i = 1; )is discarded?
They modify i , but the Expression is considered discarded because the assignment is an operator that produces a value , it’s not a great loss at all.
If n is an integer , what’s remarkable about the result of n % 10 ,and n / 10 ?
n % 10 equals the last digit in n .
And n / 10 is n with the last digit removed.
Does C have relatively many or few statements?
Few ( relatively).
Other than expression statement and return statement , what are the 3 main categories that most statements fall into ?
Selection statements.
Iteration statements.
Jump statements.
Name two selection statements.
1 - if .
2 - switch .
Name three iteration statements.
1- while .
2- do .
3 - for .
Name 4 jump statements.
1- break.
2- continue.
3- goto.
4 - return.
What do selection statements do ?
They allow a program to select a particular execution path from a set of alternatives .
Examples : if and switch statements.
What are iteration statements for? ( Briefly)
They are for looping.
Examples: while , do and for statements.
What are jump statements for ?
They cause unconditional jump to some other place in the program.
Examples : break , continue , goto and return statements.