Computer Programming Two Marks
Computer Programming Two Marks
UNIT I INTRODUCTION
PART A (2 MARKS)
1. Define computers?
A computer is a programmable machine or device that performs pre-defined or programmed
computations or controls operations that are expressible in numerical or logical terms at high speed and
with great accuracy.
(Or)
Computer is a fast operating electronic device, which automatically accepts and store input data,
processes them and produces results under the direction of step by step program.
2. What are the basic operations of Computer?
It accepts data or instructions by way of input.
It stores data.
It can process data as required by the user.
It gives results in the form of output.
It controls all operations inside a computer.
UNIT-II
2 MARKS
1. Define Compilation process.
Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an
'object' file. This step doesn't create anything the user can actually run. Instead, the compiler merely
produces the machine language instructions that correspond to the source code file that was compiled.
2. What do you meant by linking?
Linking refers to the creation of a single executable file from multiple object files.
3. Define Constants in C. Mention the types.
The constants refer to fixed values that the program may not alter during its execution. These fixed values
are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating constant, a character
constant, or a string literal.
4. What are the different data types available in C?
There are four basic data types available in C.
1. int
2. float
3. char
4. double
5. What is meant by Enumerated data type.
Enumerated data is a user defined data type in C language.Enumerated data type variables can only
assume values which have been previously declared.
Example :
enum month { jan = 1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec };
6. What are Keywords?
Keywords are certain reserved words that have standard and pre-defined meaning in C. These
keywords can be used only for their intended purpose.
7. What do you mean by variables in C?
A variable is a data name used for storing a data value.
Can be assigned different values at different times during program execution.
Can be chosen by programmer in a meaningful way so as to reflect its function in the
program.
Some examples are: Sum
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
20. Write short notes about main ( ) function in C program. (MAY 2009)
Every C program must have main ( ) function.
All functions in C, has to end with ( ) parenthesis.
It is a starting point of all C programs.
The program execution starts from the opening brace { and ends with closing brace
}, within which executable part of the program exists.
\b - Backspace
\t - Form feed
\- Single quote
\\- Backspace
\t - Tab
\r - Carriage return
\a - Alert
\ - Double quotes
UNIT III
2 MARKS
1. What is an array?
An array is a group of similar data types stored under a common name. An array is used to store a
collection of data, but it is often more useful to think of an array as a collection of variables of the same
type.
Example:
int a[10];
Here a[10] is an array with 10 values.
2. What are the main elements of an array declaration?
Array name
Type and
Size
Heap Sort
Selection sort
Bubble sort
UNIT IV
2 MARKS
1. What are functions in C?
A function is a group of statements that together perform a task. Every C program has at least one
function which is main(), and all the most trivial programs can define additional functions.
2. How will define a function in C?
Defining a Function:
The general form of a function definition in C programming language is as follows:
return_type function_name( parameter list )
{
body of the function
}
A function definition in C programming language consists of a function header and a function body. Here
are all the of a function:
Return Type
Function Name
Parameters
Function Body
3. What are the steps in writing a function in a program?
a) Function Declaration (Prototype declaration)
b) Function Callings
c) Function Definition:
4.What is the purpose of the function main()? (MAY 2009)
The function main () invokes other functions within it. It is the first function to be called when the
program starts execution.
5.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.
7. What is meant by Recursive function?
If a function calls itself again and again, then that function is called Recursive function.
Example:
void recursion()
{
recursion(); /* function calls itself */
}
int main()
{
recursion();
}
When the above code is compiled and executed, it produces the following result:
Factorial of 15 is 2004310016
9. What is dynamic memory allocation?
Allocating the memory at run time is called as dynamic memory allocation.
10. 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.
11. What is a Pointer? How a variable is declared to the pointer? (MAY 2009)
Pointer is a variable which holds the address of another variable.
Pointer Declaration:
datatype *variable-name;
Example:
int *x, c=5;
x=&a;
memory location. You can define a union with many members, but only one member can contain a value
at any given time. Unions provide an efficient way of using the same memory location for multi-purpose.
7. How to define a union in C.
To define a union, you must use the union statement in very similar was as you did while defining
structure. The union statement defines a new data type, with more than one member for your program.
The format of the union statement is as follows:
union [union tag]
{
member definition;
member definition;
...
member definition;
} [one or more union variables];
{
printf("%d\n", Road);
}
14. Define Auto storage class in C.
auto is the default storage class for all local variables.
{
int Count; auto
int Month;
}
The example above defines two variables with the same storage class. auto can only be used within
functions, i.e. local variables.
15. Define pre-processor in C.
The C Preprocessor is not part of the compiler, but is a separate step in the compilation process. In
simplistic terms, a C Preprocessor is just a text substitution tool. We'll refer to the C Preprocessor as the
CPP.
Example:
#define Substitutes a preprocessor macro
#include Inserts a particular header from another file
16. Define Macro in C.
A macro definition is independent of block structure, and is in effect from the #define directive
that defines it until either a corresponding #undef directive or the end of the compilation unit is
encountered.
Its format is: #define identifier replacement
Example:
#define TABLE_SIZE 100
int table1[TABLE_SIZE];
int table2[TABLE_SIZE];
17. What are conditional Inclusions in Preprocessor Directive?
Conditional inclusions (#ifdef, #ifndef, #if, #endif, #else and #elif)
These directives allow including or discarding part of the code of a program if a certain condition is met.
#ifdef allows a section of a program to be compiled only if the macro that is specified as the parameter
has been defined, no matter which its value is.
For example:
1 #ifdef TABLE_SIZE
2 int table[TABLE_SIZE];
3 #endif
18. What you meant by Source file Inclusion in Preprocessor directive?
Source file inclusion (#include)
This directive has also been used assiduously in other sections of this tutorial. When the preprocessor
finds an #include directive it replaces it by the entire content of the specified file. There are two ways to
specify a file to be included:
1 #include "file"
2 #include <file>
19. What is Line control?
Line control (#line)
When we compile a program and some error happens during the compiling process, the compiler shows
an error message with references to the name of the file where the error happened and a line number, so it
is easier to find the code generating the error.
The #line directive allows us to control both things, the line numbers within the code files as well as
the file name that we want that appears when an error takes place. Its format is:
#line number "filename"
Where number is the new line number that will be assigned to the next code line. The line numbers of
successive lines will be increased one by one from this point on.