Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

How Do You Determine Whether A Loop Ended Prematurely

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

 Define local block?

A local block is any portion of a C program that is enclosed by the left brace ({) and the right
brace (}). A C function contains left and right braces, and therefore anything between the two
braces is contained in a local block.

 Variables should be stored in local blocks. Yes or no?

The use of local blocks for storing variables is unusual and therefore should be avoided,


with only rare exceptions. One of these exceptions would be for debugging purposes, when
you might want to declare a local instance of a global variable to test within your function.

 A switch statement is better than multiple if statements in what all situations?

The switch statement is better than multiple if statements when there are


more than two alternatives to be selected whether the case value matches to the variable of
either character or integer type. Switch statement works better than multiple if
statements when you are giving input directly without any condition checking in
the statements. Switch statement works well when you want to increase the readability of
the code and many alternative available.

 Can a switch statement be written without a default case?

Should a "switch" statement always include a default clause? No. It should usually


include a default. Including a default clause only makes sense if there's something for it to
do, such as assert an error condition or provide a default behavior.

 Is it possible for the last case of a switch statement to skip including the break?

Even though the last case of a switch statement does not require a break statement at
the end, you should add break statements to all cases of the switch
statement, including the last case.

 Barring the for statement, where else is the comma operator used?

The comma operator is commonly used to separate variable declarations, function arguments,
and expressions.

 How do you determine whether a loop ended prematurely


Generally, loops are dependent on one or more variables. Your program can check those
variables outside the loop to ensure that the loop executed properly.

 Differentiate between goto, long jmp( ) and setjmp()?


A goto statement implements a local jump of program execution, and the longjmp()
and setjmp() functions implement a nonlocal, or far, jump of program execution.

 Explain lvalue?

An lvalue (locator value) represents an object that occupies some identifiable location in


memory (i.e. has an address). ... Every expression is either an lvalue or an rvalue. An lvalue
was defined as an expression to which a value can be assigned.

 Can an array be an lvalue?

The answer to this question is no, because an array is composed of several separate array
elements  that cannot be treated as a whole for assignment purposes.

 Explain rvalue?

rvalues are defined by exclusion, by saying that every expression is either an lvalue or


an rvalue. Therefore, from the above definition of lvalue, an rvalue is an expression that
does not represent an object occupying some identifiable location in memory.

 Is right-to-left or left-to-right order guaranteed for operator precedence?

Operator associativity can either be left-to-right or right-to-left. Means if an expression contains two


or more operators of same precedence. Then they are evaluated in either left to right or right to left
order.

 Differentiate between ++var and var++?

++var is the pre-increment operator; it increments the value of var before evaluating the


expression. Similarly, var++ is the post-increment operator; it increments the value
of var after evaluating the expression.

 Explain the function of the modulus operator?

The modulo operator, denoted by %, is an arithmetic operator.


The modulo division operator produces the remainder of an integer division. produces the
remainder when x is divided by y.

 What is the most efficient way to store flag values?

The best way to store flag values is to keep each of the values in their own integer
variable. If there are large number of flags, we can create an array of characters or
integers. 

 Explain "bit masking"?


Bit masking is simply the process of storing data truly as bits, as opposed to storing it as
chars/ints/floats. It is incredibly useful for storing certain types of data compactly and
efficiently. The idea for bit masking is based on boolean logic.

 Are bit fields portable?

Bit fields are portable, in the sense that they are a part of the C language as specified in
the standard (C11 section 6.7. 2.1). Any compiler that fails to recognise code that
uses bitfields is not standard-compliant.

 Is it better to bitshift a value than to multiply by 2?

yes, Bitshift will be fast process when compare to arithemetic operation. In order to multiply
you need to use right shift.

 What is meant by high-order and low-order bytes?

The high-order byte would be the byte that contains the largest portion of the value.


The low-order byte would be the byte that contains the smallest portion of the value. For
example, if you have a 16-bit int , and the value is 5,243, you'd write that in hex as 0x147B.

 What is the way to store 16-bit and 32-bit numbers ?

A 16-bit number takes two bytes of storage, a most significant byte and a least
significant byte. A 32-bit number takes four bytes of storages

 Explain macro and its usage

It is a series of commands and actions that can be stored and run whenever you need to
perform the task repeatedly on a regular basis.

 What purpose does preprocessor fulfill for a program?

The C preprocessor is a macro processor that is used automatically by the C compiler to


transform your program before actual compilation. It is called a macro processor because it
allows you to define macros, which are brief abbreviations for longer constructs.

 How can you avoid including a header more than once?

One easy technique to avoid multiple inclusions of the same header is to use the #ifndef
and #define preprocessor directives.

 With the help of #include , can a file other than a .h file be included?
The preprocessor will include whatever file you specify in your #include statement. ... It is,
however, unusual programming practice to put any file that does not have a . h or . hpp
extension in an #include statement.

 What is the benefit of using #define while declaring a constant?

By using #define (Macro definition) you can define a constant without consuming any


amount of memory. It helps to make our program more maintainable, because we have to
just define a constant once and we can use it any number of times anywhere (Depending
on the scope where it defined).

 What is the benefit of using enum while declaring a constant?

The use of an enumeration constant (enum) has many advantages over using the


traditional symbolic constant style of #define. These advantages include a lower
maintenance requirement, improved program readability, and better debugging capability.

 Why is it better to use an enum rather than a #define constant?

The use of an enumeration constant (enum) has many advantages over using the


traditional symbolic constant style of #define. These advantages include a lower
maintenance requirement, improved program readability, and better debugging capability.

You might also like