C Programming SQA
C Programming SQA
When using Call by Value, you are sending the value of a variable as parameter to a function,
whereas Call by Reference sends the address of the variable. Also, under Call by Value, the
value in the parameter is not affected by whatever operation that takes place, while in the
case of Call by Reference, values can be affected by the process within the function.
Source codes are codes that were written by the programmer. It is made up of the commands
and other English-like keywords that are supposed to instruct the computer what to do.
However, computers would not be able to understand source codes. Therefore, source codes
are compiled using a compiler. The resulting outputs are object codes, which are in a format
that can be understood by the computer processor. In C programming, source codes are saved
with the file extension .C, while object codes are saved with the file extension .OBJ
It is referred to as a terminating null character, and is used primarily to show the end of a
string value.
The = symbol is often used in mathematical operations. It is used to assign a value to a given
variable. On the other hand, the == symbol, also known as "equal to" or "equivalent to", is a
relational operator that is used to compare two values.
The modulus operator outputs the remainder of a division. It makes use of the percentage (%)
symbol. For example: 10 % 3 = 1, meaning when you divide 10 by 3, the remainder is 1.
6. What is a nested loop?
A nested loop is a loop that runs within another loop. Put it in another sense, you have an
inner loop that is inside an outer loop. In this scenario, the inner loop is performed a number
of times as specified by the outer loop. For each turn on the outer loop, the inner loop is first
performed.
Compilers and interpreters often deal with how program codes are executed. Interpreters
execute program codes one line at a time, while compilers take the program as a whole and
convert it into object code, before executing it. The key difference here is that in the case of
interpreters, a program may encounter syntax errors in the middle of execution, and will stop
from there. On the other hand, compilers check the syntax of the entire program and will only
proceed to execution when no syntax errors are found.
8. What are header files and what are its uses in C programming?
Header files are also known as library files. They contain two essential things: the definitions
and prototypes of functions being used in a program. Simply put, commands that you use in
C programming are actually functions that are defined from within each header files. Each
header file contains a set of functions. For example: stdio.h is a header file that contains
definition and prototypes of commands like printf and scanf.
Syntax errors are associated with mistakes in the use of a programming language. It may be a
command that was misspelled or a command that was entered in lowercase mode but was
instead entered with an upper-case character. A misplaced symbol, or lack of symbol,
somewhere within a line of code can also lead to syntax error.
Arrays contain a number of elements, depending on the size you gave it during variable
declaration. Each element is assigned a number from 0 to number of elements. To assign or
retrieve the value of a particular element, refer to the element number. For example: if you
have a declaration that says "int scores[5];", then you have 5 accessible elements, namely:
scores[0], scores[1], scores[2], scores[3] and scores[4].
11. Can I use "int" data type to store the value 32768? If not Why?
No. "int" data type is capable of storing values from -32768 to 32767. To store 32768, you
can use "long int" instead. You can also use "unsigned int", assuming you don't intend to
store negative values.
When storing multiple related data, it is a good idea to use arrays. This is because arrays are
named using only 1 word followed by an element number. For example: to store the 10 test
results of 1 student, one can use 10 different variable names (grade1, grade2, grade3...
grade10). With arrays, only 1 name is used, the rest are accessible through the index name
(grade[0], grade[1], grade[2]... grade[9]).
An ampersand & symbol must be placed before the variable name programming. Placing &
means whatever integer value is entered by the user is stored at the "address" of the variable
name. This is a common mistake for programmers, often leading to logical errors.
Random numbers are generated in C using the rand() command. For example: anyNum =
rand() will generate any integer number beginning from 0, assuming that anyNum is a
variable of type integer.
The && is also referred to as AND operator. When using this operator, all conditions
specified must be TRUE before the next action can be performed. If you have 10 conditions
and all but 1 fails to evaluate as TRUE, the entire condition statement is already evaluated as
FALSE.
17. What is || operator and how does it function in a program?
The || is also known as the OR operator in C programming. When using || to evaluate logical
conditions, any condition that evaluates to TRUE will render the entire condition statement
as TRUE.
18. What are logical errors and how does it differ from syntax errors?
Program that contains logical errors tend to pass the compilation process, but the resulting
output may not be the expected one. This happens when a wrong formula was inserted into
the code, or a wrong sequence of commands was performed. Syntax errors, on the other
hand, deal with incorrect commands that are misspelled or not recognized by the compiler.
Preprocessor directives are placed at the beginning of every C program. This is where library
files are specified, which would depend on what functions are to be used in the program.
Another use of preprocessor directive is the declaration of constants. Preprocessor directives
begin with the # symbol.
Order of precedence determines which operation must first take place in an operation
statement or conditional statement. On the top most level of precedence are the unary
operators !, +, - and &. It is followed by the regular mathematical operators (*, / and modulus
% first, followed by + and -). Next in line are the relational operators <, <=, >= and >. This is
then followed by the two equality operators == and !=. The logical operators && and || are
next evaluated. On the last level is the assignment operator =.
Yes, you don't have to write a separate assignment statement after the variable declaration,
unless you plan to change it later on. For example: char planet[15] = "Earth"; does two
things: it declares a string variable named planet, then initializes it with the value "Earth".
22. What are run-time errors?
These are errors that occur while the program is being executed. One common instance
wherein run-time error can happen is when you are trying to divide a number by zero. When
run-time errors occur, program execution will pause, showing which program line caused the
error.
These 2 functions basically perform the same action, which is to get the absolute value of the
given value. Abs() is used for integer values, while fabs() is used for floating type numbers.
Also, the prototype for abs() is under <stdlib.h>, while fabs() is under <math.h>.
When you create and use functions that need to perform an action on some given values, you
need to pass these given values to that function. The values that are being passed into the
called function are referred to as actual arguments.
In using functions in a C program, formal parameters contain the values that were passed by
the calling function. The values are substituted in these formal parameters and used in
whatever operations as indicated within the main body of the called function.
26. What are global variables and how do you declare them?
Global variables are variables that can be accessed and manipulated anywhere in the
program. To make a variable global, place the variable declaration on the upper portion of
the program, just after the preprocessor directives section.
Enumerated types allow the programmer to use more meaningful words as values to a
variable. Each item in the enumerated type variable is actually associated with a numeric
code. For example, one can create an enumerated type variable named DAYS whose values
are Monday, Tuesday... Sunday.
28. Is it possible to have a function as a parameter in another function?
Yes, that is allowed in C programming. You just need to include the entire function prototype
into the parameter field of the other function where it is to be used.
Both functions will accept a character input value from the user. When using getch(), the key
that was pressed will not appear on the screen, and is automatically captured and assigned to
a variable. When using getche(), the key that was pressed by the user will appear on the
screen, while at the same time being assigned to a variable.
Yes, it is possible to create a customized header file. Just include in it the function prototypes
that you want to use in your program, and use the #include directive followed by the name of
your header file.
If the amount of data stored in a file is fairly large, the use of random access will allow you
to search through it quicker. If it had been a sequential access file, you would have to go
through one record at a time until you reach the target data. A random access file lets you
jump directly to the target address where data is located.
If a break statement was not placed at the end of a particular case portion? It will move on to
the next case portion, possibly causing incorrect output.
34. Describe how arrays can be passed to a user defined function.
One thing to note is that you cannot pass the entire array to a function. Instead, you pass to it
a pointer that will point to the array first element in memory. To do this, you indicate the
name of the array without the brackets.
Yes, it is possible to pass an entire structure to a function in a call by method style. However,
some programmers prefer declaring the structure globally, then pass a variable of that
structure type to a function. This method helps maintain consistency and uniformity in terms
of argument type.
The gets() function allows a full line data entry from the user. When the user presses the
enter key to end the input, the entire line of characters is stored to a string variable. Note that
the enter key is not included in the variable, but instead a null terminator \0 is placed after the
last character.
It’s a pointer variable which can hold the address of another pointer variable. It de-refers
twice to point to the data held by the designated pointer variable.
Yes, it can be but cannot be executed, as the execution requires main() function definition.
39. What is keyword auto for?
By default every local variable of the function is automatic (auto). In the below function both
the variables ‘i’ and ‘j’ are automatic variables.
void f() {
int i;
auto int j;
A static local variable retains its value between the function call and the default value is 0.
The following function will print 1 2 3 if called thrice.
void f() {
static int i;
++i;
printf(“%d “,i);
}
If a global variable is static then its visibility is limited to the same source code.
while(0 == 0)
{
…………
…………
}
42. How to create enumeration constants?
Enumerated data type is a user defined data type. Enumerated data type helps in creating a
list of identifiers also called as symbolic numeric constants of type int. enum keyword is used
to create enumeration constant.
++a is known as pre-increment where the value is incremented by one and then the operation
is done. a++ is known as post increment where the operation is done first and then the value
is incremented by one.
No Break Continue
i. Takes the control to outsideof Takes control to the beginning ofthe
the loop. loop.
iv. Size of(array name) gives the Sizeof(pointer name) returns the
number of bytes occupied by the number of bytes used to store the
array. pointer variable.
49. State the advantages of user defined functions over pre-defined function.
A user defined function allows the programmer to define the exact function of the module as
per requirement. This may not be the case with predefined function. It may or may not serve
the desired purpose completely.
A user defined function gives flexibility to the programmer to use optimal programming
instructions, which is not possible in predefined function.
50. Write the advantages and disadvantages of recursion.
Recursion makes program elegant and cleaner. All algorithms can be defined recursively
which makes it easier to visualize and prove. If the speed of the program is vital then, you
should avoid using recursion. Recursions use more memory and are generally slow. Instead,
you can use loop.
Macros are more efficient (and faster) than function, because their corresponding code is
inserted directly at the point where the macro is called. There is no overhead involved in
using a macro like there is in placing a call to a function. However, macros are generally
small and cannot handle large, complex coding constructs. In cases where large, complex
constructs are to handled, functions are more suited, additionally; macros are expanded
inline, which means that the code is replicated for each occurrence of a macro.
Arrays Structures
An array cannot have bit fields. A structure may contain bit fields.
Structure Union
Every member has its own memory. All members use the same memory.
Interpreter Compiler
Interpreter translates just one statement of the Compiler scans the entire program and translates
program at a time into machine code. the whole of it into machine code at once.
An interpreter takes very less time to analyze the A compiler takes a lot of time to analyze the
source code. However, the overall time to source code. However, the overall time taken to
execute the process is much slower. execute the process is much faster.
An interpreter does not generate an intermediary A compiler always generates an intermediary
code. Hence, an interpreter is highly efficient in object code. It will need further linking. Hence
terms of its memory. more memory is needed.
Keeps translating the program continuously till A compiler generates the error message only
the first error is confronted. If any error is after it scans the complete program and hence
spotted, it stops working and hence debugging debugging is relatively harder while working
becomes easy. with a compiler.
Interpreters are used by programming languages Compliers are used by programming languages
like Ruby and Python for example. like C and C++ for example.
59. int vs long int
This is entry-controlled loop. It checks This is exit control loop. Checks condition
condition before entering into loop when coming out from loop
The while loop may run zero or more times Do-While may run more than one times but at
least once.
The variable of test condition must be The variable for loop condition may also be
initialized prior to entering into the loop initialized in the loop also.
while(condition){ do{
//statement //statement
} }while(condition);
61. Array Vs Structure
ARRAY STRUCTURE
Array refers to a collection consisting of Structure refers to a collection consisting of
elements of homogeneous data type. elements of heterogeneous data type.
Array uses subscripts or “[ ]” (square bracket) Structure uses “.” (Dot operator) for element
for element access access
Array size is fixed and is basically the number Structure size is not fixed as each element of
of elements multiplied by the size of an Structure can be of different type and size.
element.