0% found this document useful (0 votes)
19 views16 pages

C Programming SQA

Uploaded by

sadabjaowad69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
19 views16 pages

C Programming SQA

Uploaded by

sadabjaowad69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 16

C Programming SQA

1. What is the difference between Call by Value and Call by Reference?

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.

2. Differentiate Source Codes from Object Codes

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

3. What is the use of a '\0' character?

It is referred to as a terminating null character, and is used primarily to show the end of a
string value.

4. What is the difference between the = symbol and == symbol?

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.

5. What is the modulus operator?

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.

7. Compare between compilers and interpreters.

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.

9. What is syntax error?

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.

10. How do you access the values within an array?

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.

12. What is the advantage of an array over individual variables?

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]).

13. What is wrong in this statement? scanf("%d", programming);

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.

14. How do you generate random numbers in C?

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.

15. What is debugging?


Debugging is the process of identifying errors within a program. During program
compilation, errors that are found will stop the program from executing completely. At this
state, the programmer would look into the possible portions where the error occurred.
Debugging ensures the removal of errors, and plays an important role in ensuring that the
expected program output is met.

16. What does the && operator do in a program code?

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.

19. What are preprocessor directives?

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.

20. Describe the order of precedence with regards to operators in C.

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 =.

21. Is it possible to initialize a variable at the time it was declared?

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.

23. What is the difference between functions abs() and fabs()?

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>.

24. What are actual arguments?

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.

25. What are formal parameters?

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.

27. What are enumerated types?

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.

29. What are multidimensional arrays?

Multidimensional arrays are capable of storing data in a two or more-dimensional structure.


For example, you can use a 2-dimensional array to store the current position of pieces in a
chess game, or position of players in a tic-tac-toe program.

30. What is the difference between functions getch() and getche()?

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.

31. is it possible to create your own header files?

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.

32. What is the advantage of a random-access 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.

33. In a switch statement, what will happen if a break statement is omitted?

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.

35. Can you pass an entire structure to functions?

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.

36. What is gets() function?

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.

37. What is a pointer on pointer?

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.

Eg: int x = 5, *p=&x, **q=&p;

Therefore ‘x’ can be accessed by **q.

38. Can a program be compiled without main() function?

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;

NOTE − A global variable can’t be an automatic variable.

40. What is a static variable?

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.

41. What is an infinite loop?

A loop executing repeatedly as the loop-expression always evaluates to true such as

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.

Syntax : enum identifier{value1, value2,…….,value n};


Example : enum holidays{sun, sat};

43. Invent the difference between ++a and a++.

++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.

44. Differentiate break and continue statement.

No Break Continue
i. Takes the control to outsideof Takes control to the beginning ofthe
the loop. loop.

ii. It used in both looping and It is used only in looping


switch statements. statements.

45. How to create a two dimensional array?


Two dimensional arrays are stored in a row-column matrix, where the left index indicates the
row and right matrix indicates the column.

Syntax : data_type array_name[row_size][column_size];


Example : int mat[3][3];
46. What is the role of strrev( )?
The function strrev( ) is used to reverse a string. This function takes only one argument and
return only one argument.
Syntax : strrev(string_to_be_reversed);

47. What is the difference between an array and pointer?

No. Array Pointer


i. Array allocates space Pointer is explicitly assigned topoint
automatically. to an allocated space

ii. It cannot be resized It can be resized using realloc ()


iii. It cannot be reassigned Pointers can be reassigned.

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.

48. What is a function prototype?

Function prototype is a function declaration statement.

Syntax : return_type function_name( parameters_list)

Example: int factorial(int);

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.

51. Is it better to use a macro or a function?

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.

52. What are the uses of pointer?


• Saves Memory Space
• Used for dynamic memory allocation
• Faster execution
• Used to pass array of values to a function as a single argument

53. Compare arrays and structures.

Arrays Structures

An array is a collection of data items of A structure is a collection of data items of Different


same data type. Arrays can only be data types. Structures can be declared and defined.
declared.

There is no keyword for arrays. The keyword for structures is struct.

An array cannot have bit fields. A structure may contain bit fields.

An array name represents the A structure name is known as tag. It is a


address of the starting element. Shorthand notation of the declaration.
54. Difference between structure and union.

Structure Union

Every member has its own memory. All members use the same memory.

The keyword used is struct. The keyword used is union.

All members occupy separate memory


location, hence different interpretations of Different interpretations for the same
the same memorylocation are not possible. memory location are possible.
Consumesmore space compared to union. Conservation of memory is possible

55. What are the various dynamic memory allocation functions?


• malloc() - Used to allocate blocks of memory in required size of bytes.
• free() - Used to release previously allocated memory space.
• calloc() - Used to allocate memory space for an array of elements.
• realloac() - Used to modify the size of the previously allocated memory space.

56. Differentiate between for loop and while loop.


Parameter For loop While loop
of
Comparison
Command The structure of for loop is Structure of while loop is

for(initial condition; number of While(condition)


iterations) {statements;//body}
{//body of the loop}
Iterations Iterates for a preset number of Iterates till a condition is met.
times.
Condition In the absence of a condition, In the absence of a condition, while
the loop iterates for an infinite loop shows an error.
number of times till it reaches
break command.
Initialization Initialization in for loop is done Initialization is done every time the
only once when the program loop is iterated.
starts.
Use Used to obtain the result only Used to satisfy the condition when
when the number of iterations is the number of iterations is unknown.
known.
57. Global Variable Vs Local Variable

Global Variable Local Variable


Global variables are declared outside all the Local Variables are declared within a function
function blocks. block.
The scope remains throughout the program. The scope is limited and remains within the
function only in which they are declared.
Any change in global variable affects the Any change in the local variable does not
whole program, wherever it is being used. affect other functions of the program.
If the global variable is not initialized, it takes If the local variable is not initialized, it takes
zero by default. the garbage value by default.
Global variables are stored in the data Local variables are stored in a stack in
segment of memory. memory.

58. Interpreter Vs Compiler

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

int long int

The datatype int is of 32-bits. The data type long is of 64-bits.


If counted in bytes, int is 4 bytes. If counted in bytes, long is 8 bytes.
In Java the range of type int is –2,147,483,648 to In Java the range of type long is
2,147,483,647. –9,223,372,036,854,775,808 to
9,223,372,036,854,775,807.
Keyword used to declare a variable of int type is Keyword used to declare a variable of long type
"int". is "long".
Memory required to store an int variable is less Memory required to store a long variable is
as compared to long. larger as compared to int.

60. While Loop Vs Do While Loop

While Loop Do-While Loop

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

Instantiation of Array objects is not possible. Instantiation of Structure objects is possible.

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.

Bit filed is not possible in an Array. Bit filed is possible in an Structure.

Arrays is a non-primitive datatype Structure is a user-defined datatype.

data_type array_name[size]; struct sruct_name{ data_type1 ele1; data_type2


ele2; };

62. High Level Vs Low Level Language

High Level Language Low Level Language

It is programmer friendly language. It is a machine friendly language.


High level language is less memory efficient. Low level language is high memory efficient.
It is easy to understand. It is tough to understand.
It is simple to debug. It is complex to debug comparatively.
It is simple to maintain. It is complex to maintain comparatively.
It is portable. It is non-portable.
It can run on any platform. It is machine-dependent.
It needs compiler or interpreter for translation. It needs assembler for translation.
It is used widely for programming. It is not commonly used now-a-days in
programming
63. What are the differences between compile time error and run time error?

Parameters Compile Time Errors Runtime Errors


Detection Compilers can easily detect compile- A compiler cannot easily detect a runtime error.
time errors during the development of Thus, we need to identify it during the execution
code. of code.
Reference A compile-time error generally refers A runtime error refers to the error that we
to the errors that correspond to the encounter during the code execution during
semantics or syntax. runtime.
Fixation We can easily fix a compile-time error A compiler cannot identify a runtime error. But
during the development of code. we can fix it after the execution of code and
identification of the code in prior.

You might also like