Sunteți pe pagina 1din 21

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

GE6151- COMPUTER PROGRAMMMING


TWO MARKS
UNIT 1
1. Define Computer. Give its expansion.
The computer is an electronic device designed in such a way that it automatically accepts and stores input data,
process them and produce the desired output.
COMPUTER: Commonly Operating Machine Particularly Used for Trade and Education Research.
2. Define Data and Information.
Data: It is the facts about anything.[raw data]
Information: The processed data is called information.
3. What are the Basic Operations of a computer?
1.Input
2.Process
3.Output
4.Storing
5.Controlling
4. What is input and output?
Input is the process of capturing the raw data or information. By using this we can do any process.
Output is the result which comes from the transformation process.
Transformation is the process in which input is converted into output.
5. Define storing.
Storing is the process of saving the data or information, so that they can be retrieved whenever needed.
6. Define controlling.
Controlling is the process of directing the manner in which all the operations are to be performed.
7.What are characteristics of computers?
The characteristic of the computers are speed, accuracy, automation, endurance, storage, versatility, cost reduction,
no intelligent quotient(IQ).
8. Give the applications of computer.
Word processing
Internet
Digital video or audio composition
Weather analysis
Market Analysis

Accounting
9. Define Hardware and Software.
The term Hardware is applied to any physical equipment in the computer system, such as machinery.
Software is basically the set of instructions grouped into programs that make the computer to function in the
desired way. It is a collection of programs to perform a particular task.
10. Give the basic computer functional units?
Input Unit
Central Processing Unit
Output Unit
11. Define types of programming languages.
Machine Language: It uses only 0s and 1s to represent data and the instructions.
Assembly Language: It uses only mnemonic codes to represent data and the information.
High-Level Language: These Languages are written using a set of words and symbols by accessing specific
rules and syntax.
12. List out the operations performed by the central processing unit.
It performs all calculations and all decisions.
It controls and co-ordinates all units of the computer.
It interprets instructions of a program.
It stores data temporarily and monitors external request.
13. Define operating system.
A collection of programs used to control and co-ordinate the computer system is called operating system. Operating
system manages and coordinates the functions performed by the computer system hardware, I/O devices, including the CPU,
secondary storage devices, communication and network equipment.
14. Define bits & bytes?
Bits: Bits is known as binary digit. Each bit value can be 0 or 1
Byte :Bytes are most commonly made up of eight bits used to store a single character.
15. Define RAM.
Random Access Memory (RAM) is a temporary memory where the computer stores all the data it receives from input
and the results it gets through calculations.
16. Define ROM.
Read Only Memory (ROM) is permanently in-built in the computer at the time of production. It stores a set of
instructions permanently which instructs the computer how to work.
17. What are the types of ROM?
PROM Programmable ROM
EPROM Erasable PROM

EEPROMS Electrically Erasable PROM


Flash ROMS.
18. Differentiate between static and dynamic RAM .
S.No
Static RAM
1.
Retain its content as long as power is available.
2.
Constantly maintained data.
3.
Less number of chips used.
4.
Very fast.
19. Differentiate between RAM and ROM.
S.No
1.
2.
3.
4.
5.

Dynamic RAM
It has short data life.
Need to be refreshed to maintain data in it.
More number of chips used.
Slow compared to Static RAM.

ROM
It is a non-volatile memory
The content are permanent
Available in high storage capacity
Processor speed is low
Cost effective

RAM
It is a volatile memory
The content are temporary
Available in small storage capacity
Processor speed is high
Cost is very high

20. Define cache memory?


A small memory between CPU and main memory is called cache memory. The access time is closer to the processing
speed of the CPU. Cache memory acts as a high speed buffer between CPU and main memory. It is used to temporarily store
active data and instructions during processing.
21. List out the cables used to connecting computers with peripherals?
Power card
Monitor cable
Mouse cable
Keyboard cable
Printer cable
22. What are the functions performed by the input unit?
The input unit accepts data and instructions from the user and convert it into a form that the computer can understand
and then supply the converted data to the computer for further processing.
Input unit consists of one or more input devices. Some of the input devices are: Keyboard, Mouse , Light Pen,
Trackball etc.
23. What are the functions performed by the output unit?
The output unit provides the information and results of a computation to the user.
The output unit also converts the binary data output into a form that the user can understand.
Some of the output devices are: printer, monitor, hard disk etc.

24. What is Algorithm?

An algorithm is the step by step instructions of a program. Algorithm means the logic of a program. It is a
step-by-step description of how to arrive at a solution of a given problem.
25. Define flowchart.

It is a pictorial representation of an algorithm. It contains some standard symbols. The steps are drawn by
using different shapes and the flow is indicated by arrows.
26. What is Pseudocode?

Pseudo means imitation of false and code refers to the instruction written in the programming
language. Pseudo code is programming analysis tool that is used for planning program logic.
NUMBER SYSTEM

1. Convert (266.25) 10 to octal form


2. Convert (10A4)16 to binary form
3. Convert (110111)2 to decimal equivalent
4. Convert (11001111.11)2 to octal form

FLOW CHARTS

1. Draw the flowchart to find the biggest among two numbers.


2. Draw the flowchart to reverse a given multi-digit number.
3. Draw a flowchart to find the roots of the quadratic equation.
4. Draw a flowchart to find the number is prime or not.

UNIT 2
1.Define Problem formulation.
Problem formulation is a plan for collecting requirements and utilizing data about a problem.
It helps to obtain the desired information about the problem.
2.Define Problem solving.
It is the process of transforming the description of a problem into a solution by using our knowledge of the problem
domain by using appropriate techniques and tools.
3.What is documentation?
It provides a written description of each step of the program.
It allows the user to operate the program correctly.
4. Give any four features of C language?
Low level language support.
Structured programming.
Program portability.

Compactness, Reusability & Acceptability.


5. What are the major advantages in C?
Portable language.
Collection of library files.
Compiler based language.
Support good graphics.
Supports number of operators.
Supports arrays, pointers, structures and unions.
6 .Give the structure of a C program.
Documentation
Pre-Processor Statements
Global declaration
Main( ) Function
Local Declaration
Program Statements.
7. What is meant by comments.
Comment is a sequence of characters beginning with /* combination.
It is treated as a single white space by the compiler.
Ex: /* Program to find the sum of two numbers */

8. Write the steps to compile a C program.


Preprocessing, Compiling , Assembling, Linking.
9. What is preprocessing?
It is the first stage of compilation.
It includes header files like stdio.h , conio.h etc.
It processes all the preprocessor statements. Example: #include, # define etc.
10. Define compiler.
It is a program, which is used to convert the high-level language programs into machine language.
It takes the output of the preprocessor and generates assembly code.
11. Define Assembler.
It is a program, which is used to convert the assembly level language programs into machine language.
It takes the assembly code and generates binary output.
12. Define Interpreter.
It is a program, it takes one statement of high-level language program, translates it into machine language instruction
and the immediately executes the resulting machine language instruction and so on.
13. What is linker?
It is a program, it takes one or more object files as input and combines them to produce a single executable file.
14. What is meant by C character set?
A character set defines the valid characters that can be used in source program.
It includes alphabets, digits and special characters.
15. What is meant C tokens?
C tokens are the building blocks in C language which are constructed together to write a C program.
It includes constants, identifiers, keywords, strings, operators, special symbols.
16. Define identifiers?
Identifiers are names given to various program elements such as variable, functions and arrays etc.
17. Define constants? What are the types of constants?
Constant means that it does not change during the execution of program.
Types of constants are:
Numeric constants integer constants, real constants
Character constants single character constants, string constants
18. Define string constant.
A sequence or group of characters is used as a constant value which is written within double quotes.
Example: char name = prince ;

19. What is meant by variables?


Variables are memory locations used by a program to store data.
A unique name should be given to each variable by the user.
Syntax: datatype variable-name ;
20. Define data types?
A datatype is used to define a variable before its use.
A datatype will assign storage for the variable and define the type of data.
Example: int, float
21. What are different data types available in C?
Int integer numbers
Float floating point numbers
Char characters
Double long floating point numbers.
22. What are keywords?
There are some reserved words called keywords that have predefined meaning in C language which cannot be
changed. Example: break, continue, for etc.
23. What is a operator and an operand?
An operator is a symbol that specifies an operation to be performed on operands.
Example: +, -, *, / are called arithmetic operators.
The data items that the operators act upon are called operands.
Example: a+b. In this a and b are called operands.
24. What are the types of operators?
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Increment and decrement operators
Conditional operators ( Ternary operator )
Bit wise operators
Special operators
25. What is difference between logical AND and bit wise AND?

Logical AND only used in conjunction with two expressions to test more than one condition. If both the
condition are true then returns one, if false then return zero. Bit wise AND only used in bit wise manipulation. It is
an unary operator.
26. Define expression
An expression is a combination of variables, constants and operators.
An expression is evaluated using assignment operator.
Example: x = a*b c ;
27. What are types of I/O statements available in C?

Formatted functions

printf( ), scanf( )

Unformatted functions

gets( ), getchar( ),puts( ),putchar( )

input/output functions

28. What are the differences between while and dowhile loop?

While

Do while

In the while loop the condition is first


executed. If the condition is true then it executes
the body of the loop. When the condition is false
it comes out of the loop.
While(condition)
{
Statements;
}

In the dowhile loop first the statement is


executed and then the condition is checked. The do
while loop will execute at least one time even though
the condition is false at the very first time.
Do
{
Statements;
}while(condition)

29. Define nested for loop?


A for loop contains another for loop inside in it, is called a nested for loop.
Example:
main( )
{
int a[3][3] = { 1,2,3,4,5,6,7,8,9 };
for( i=0;i<3;i++)
for(j=0;j<3;j++)
printf(%d, a[i][j]);
}
30. What is meant by break statement?

The break statement is used to terminate the loop when the keyword break is used inside any c loop control
automatically transferred to the first statement after the loop. Break is usually associated with an if statement.
31. Define goto statement?

The goto statement transfer control unconditionally from one place to another place in the program.
32. What is meant by continue statement?
When continue statement is encountered inside a loop, control automatically passes to the beginning of the loop.

33.List out the jumping statements.


Goto
Continue
Break
34. Differentiate operators and operands.
Operators
Operators are symbols.
Opertaor defines what operation
performed on the variables.

Operands
Operands are data values.
is Operands are the variables on which the
operation is performed.

35. Write the syntax of for loop in C. Write a for loop statement to print numbers from 10 to 1.
For(initialize counter; test condition;increment/decrement)
{
Statements;
}
36. Write a program to accept an input from user and prints it.
#include<stdio.h>
#include<conio.h>
void main( )
{
int a;
printf(enter an integer);
scanf(%d,&a);
printf(The value is %d, a);
getch();
}
PROGRAMS

For(int i=10;i>=1;i--)
{
Printf(%d,i);
}

Unit III
1. Define array?

An array is a collection of similar data items stored under a common name.


A collection of elements belonging to the same datatype is called array.
Example: int marks[5];
2. How to declare an array? OR How to declare a 1D array ?

Syntax:

<data type> <array name> [size];

where <data type> refers to the type of the array variable.


<array name> refers to the name of the array.
[size] refers to the number of elements in the array.
Example: int marks[10];
3. How to initialize an array? OR How to initialize a 1D array ?

Syntax: data type array name [ size] = { value1, value2,.., value n };


The values are specified in the curly brace and they are separated by commas.
Example: int marks [5] = { 50, 60, 70, 80, 90 };
float marks[5] = { 50.5, 60.5, 70.5, 80.5, 90.5 };
4.Write the classification of array?

Arrays can be classified into two types:


One dimensional array
Multi-dimensional array -> two-dimensional, three-dimensional, n-dimensional.
5. Define One-dimensional array?

10

The array which is used to represent and store data in a single dimension is called one dimensional array.
Declaration of One dimensional array

Syntax: <data type> <array name> [size];


Example: int marks[10];
6. What is meant by Two-dimensional arrays?

The array which is used to represent and store data in two dimensions called two dimensional array.
Declaration of Two dimensional array

Syntax: <data type> <array name> [row size] [column size];


Example: int a[3][3];
7. How to declare a 2D array?
Declaration of Two dimensional array

Syntax: <data type> <array name> [row size] [column size];


where <data type> refers to the type of the array variable.
<array name> refers to the name of the array.
[row size] refers to the number of rows in the array.
[column size] refers to the number of columns in the array.
Example: int a[3][3];
8. How to initialize a 2D array?

Syntax: <data type><array name>[row size][column size] ={value1, value2,, value n };


The values are specified in the curly brace and they are separated by commas.
Example: int a[3][3]= { 1,2,3,4,5,6,7,8,9};
9. What are multi-dimensional arrays?
Arrays with more than one dimension is are called multi-dimensional arrays.
Example : 2D array : int a[3][3]
3D array : int a[3][3][3]
10. Compare static array and dynamic array.

11

Static Array
If the range of an array is included in the

Dynamic Array
If the range of an array is not included in the

array definition, it is called static array.


Static arrays cant be changed.

array definition, it is called dynamic array.


Dynamic arrays can be changed during runtime.

11. What is the need of an array variable?


It is used to represent a list of numbers or names
It is also used represent the tabular data in two, three or more dimensions.
12. Define string?

A string is a group of characters.


It is also called character array.
It is enclosed within double quotes. Eg: Hai
13. How to declare string variables?
Declaration

- It is the process of defining the string variable, the size of the string and its type.

Syntax: <data type> <string name> [size];


char string-name [size];
where char - character datatype.
string name name of the sting ( user defined)
[size] refers to the number of characters in the string.
Example: char str[6];
14. How to initialize string variables?
Initialization- It is the process of assigning the values either character by character or directly the string value.

char string name [size] = value;


char str[5] = { n , a , m , e }; // values are assigned character by character
char str[5] = name; // entire string is directly assigned.
char str[ ] = name; // size of the string is not mentioned.
15.What are the ways to read a string?
1. scanf ( )
Definition:

It is a formatted

2. gets ( )
It is an unformatted

3. getchar ( )
It is an unformatted

input function to read a single input function to read a group input function to read a single
character or word from the input of characters until an enter key character at a time.
12

device and the format of the is pressed.


string is %s .
Syntax:

Syntax:

Syntax:

scanf( %s, &variable-name);

gets(variable-name);

variable-name = getchar( );

16. What are the ways to write a string?


1. printf ( )
Definition:

2. puts ( )

It is a formatted

3. putchar ( )

It is an unformatted

It is an unformatted

output function to write a single input function to read a group input function to read a single
character or word to the output of characters until an enter key character at a time.
device and the format of the is pressed.
string is %s .
Syntax:

Syntax:

Syntax:

printf( %s, variable-name);

puts(variable-name);

variable-name = putchar( );

17. List some string functions?


strlen( ) string length
strcpy( )- string copy
strcat( )- string concatenation
strcmp( )- string comparison
strlwr( )- string lowercase
strupr( )- string uppercase
strrev( )- string reverse
strstr( ) - substring
18. What is string arrays?
A two dimensional array is used to create an array of strings.
Example: char name[20][10];
Here 20 is the number of strings and 10 is the maximum length of each string.
19.What is sorting?
Sorting is the process of arranging a set of similar information into an increasing or decreasing order.
Some commonly used sorting methods are bubble sort, quick sort, merge sort, insertion sort etc.
20. Define searching.

13

The process of finding a target element among a list of elements.


The commonly used searching methods are:

linear search.

binary search.

21. List the characteristics of array.


All the elements of an array share the same name.

An array is referred by index number.


An array index number always begins with zero.
An array consists of continuous memory locations.
Array memory size = size of datatype * size of array.
22. Write a C program to read a string as input and print the same as output.
#include<stdio.h>
void main( )
{
char str[50];
printf(Enter a string);
scanf(%s,str);
printf(The entered string is %s, str);
}
23. Write a C program to reverse a given string.
#include<stdio.h>
#include<string.h>
void main( )
{
char string[10]=god;
strrev(string);
printf(The reversed string is %s,string);
}
24. Write a C program to check the string is palindrome or not
#include<stdio.h>
#include<string.h>
void main( )
{
char s1[20],s2[20];
int result;
puts("Enter a String\n");
gets(s1);
strcpy(s2,s1);
strrev(s1);
result=strcmp(s1,s2);
if(result==0)
puts("The Given String is Palindrome\n");
14

else
puts("The Given String is Not Palindrome\n");
getch( );
}
Unit 4
1. What is Function?
A set of instructions to perform specific tasks that occur several times in the main program is called a function.
Functions are the building blocks in a program. Functions are also called as subprograms.
2. What are the types of function?
1.Predefined functions
Predefined functions are created by the person who designed and created C compiler. These are also called as
library functions. Example: log(x), sin(x) etc.
2.User defined functions
User defined functions are created by user according to their requirements. They are used to perform a
particular task. They can be given after or before the main function.
3. How to define a Function?
Syntax:

return_type

function_name (parameter_list)

// function header

{
local declaration;
executable statements;

// function body

return;
}
4. List out the function prototypes?
Function without arguments and without return values.
Function with arguments and without return values.
Function with arguments and with return values.
Function without arguments and with return values.
5. What are the three elements of user defined function?
Function definition
Function declaration
Function call
6. What is a parameter? What are the types of parameters?
Parameters serve as input data to the function to carry out the specified task.
Parameters are classified into two types. 1. Formal Parameters 2. Actual Parameters.
7. What is a meant by actual parameter and formal parameter?

15

The formal parameters allow information to be transferred from the calling program. The parameters used in the
function definition.
The actual parameters are the arguments in the calling function. The parameters used in the function call.

8. What are the methods of passing a parameter?


Whenever a function is called, the sequence of executable statements is executed. The values passed to a function for
processing are called argument.
The parameter passing methods are
1. Pass by value or call by value
2. Pass by reference or call by reference
9. Differentiate Call by value and Call by reference?
Pass by value

Pass by reference

The values are directly passed to a function. It is The address of a variable is passed to a function. It
also called call by value.

is also called call by reference.

New local memories are allocated for formal New local memories are not allocated for formal
parameters and the values of actual parameters parameters and the values of actual parameters are
are copied into the formal parameters.

not copied into the formal parameters.

10. Define recursion?


Recursion is a process by which a function calls itself repeatedly until some specified condition is met.
Syntax:

function( )
{
function( );
}

In the above function the function( ) is called themselves continuously.


11. What are the advantages and disadvantages of recursive functions?

Advantages
It is useful for branching processes.
It is written with less number of statements.
Recursive functions are effective.
Disadvantages
It is difficult to think the logic of a recursive function.
It is also difficult to debug the same.
16

12. What is a pointer?

Pointer is a variable which holds the address of another variable.


A pointer is a derived data type in C.
Syntax:

data-type *variable-name;

13. What are the steps to initialize a pointer variable?

Declare a pointer variable and note down the data-type.


Declare a normal variable with same data-type.
Initialize the normal variable and assign some value to it.
Now, initialize pointer by assigning the address of normal variable to pointer variable.
14. What is meant by null pointer?

If the pointer does not have exact address to be assigned when the NULL value is assigned.
A pointer that is assigned NULL is called a null pointer.
15. Define arrays of pointer?

Pointer is a variable which holds the address of another variable.


Array is a collection of similar data stored under a common name continuously in memory.
Array name act as a pointer.
The array name always points the first element of the array.
Unit 5
1.Define structure ?

A structure is a collection of heterogeneous data type in a sequence.

A structure is a collection of variable under a single name. Structure is a user defined data type.
The keyword struct declares a structure to hold the details of data fields. These fields are called structure members.
2. What is the need for structure datatype?
Each element in an array must be of the same data type. All the data type can't be expressed in a single array. We
have to declare different arrays for each data type. But there will be a big increase in source code. Hence arrays cannot be
useful here. It is often desirable to group data of different types and work with that grouped data as one entity. The power to
accomplish this grouping with a new data type is called a structure.
3. Define structure declaration. Or How to declare a structure?
A structure variable declaration is similar to declaration of variables of any other data types. The list of fields used to
declare structure variables are:
1. Keyword struct
2. Structure name

17

3. A terminating semicolon
4. List of variable names seperated by commas.
4. What are the rules to declare a structure?
Rule-1: A structure must end with semicolon.
Rule-2: Each structure element must be terminated.
Rule-3: Usually, a structure appears at the top of the source program.
Rule-4: The structure element must be accessed by structure variable with dot(.) operator.
5. Give the syntax for structure declaration.
Syntax

Example

struct structure-name

struct book
{
char title[50];
char author[50];
char subject[50];
int book-id;
} book1,book2;

{
struct_element 1;
struct_element 2;

struct_element n;
}one or more structure variables;
6.How structure elements can be accessed ?

The process of using the structure members by its corresponding structure variable in a C program is called accessing
structure member. To access any member of a structure, we use the member access operator (.)
Syntax

structure-name . structure-member ;

7. Differentiate array and structure


S.No
1

Structure
A structure is a collection of heterogeneous data
type in a sequence.

Array
An array is a collection of homogeneous data type.

Structure is a user defined data type.

An array is a derived data type.

Structure must be declared and defined.

Array is a built-in data type.

A structure element can be added if necessary.

An array can be increased or decreased.

The structure members can be accessed using

We can access array like normal variable with its

structure variables.
8. Define Union?

position.

A union is a collection of heterogeneous data type in a sequence.


Union is a user defined data type used to stored data under unique variable name at single memory location.
To declare a union data type,Union keyword is used. Union is similar to structure.
9. Define union declaration. Or How to declare a union?
A union variable declaration is similar to declaration of variables of any other data types.

18

The list of fields used to declare union variables are:


1. Keyword union
2. Union name
3. A terminating semicolon
4. List of variable names seperated by commas.
10. Give the syntax for union declaration.
Syntax

Example

union union-name

union book
{
char title[50];
char author[50];
char subject[50];
int book-id;
} book1,book2;

{
union_element 1;
union_element 2;

union_element n;
} one or more union variables;
11. What are the rules to declare a union?
The following rules should be followed while declaring a union.
Rule-1: A union must end with semicolon.
Rule-2: Each union element must be terminated.

Rule-3: Usually, a union appears at the top of the source program.


Rule-4: The union element must be accessed by union variable with dot(.) operator.
12. How union elements can be accessed?
The process of using the union members by its corresponding union variable in a C program is called accessing union
member. To access any member of a union, we use the member access operator (.)
Syntax

union-name . union-member ;

13.What are the advantages of union over structure?


Saves space.
Helps to view a data item in two or more different ways.
Helps to build heterogeneous data structures.
Members of a union share the same memory.
The size of a union is the size of the largest member.
14.Differentiate Union and structure.
UNION
The keyword union is used to define a union.

STRUCTURE
The keyword struct is used to define a structure.

When a variable is associated with a union, the compiler When a variable is associated with a structure, the compiler

19

allocates the memory by considering the size of the largest allocates the memory for each member. The size of structure
memory. So, size of union is equal to the size of largest is greater or equal to the sum of sizes of its members. The
member.

smaller members may end with unused stack bytes.

Memory allocated is shared by individual members of union. Each member within a structure is assigned unique storage
area of location.
15. Define nested structure?
If a structure contain more than one structure as its members is known as nested structure.
Example
struct date
{
int date,month,year;
}dob;
struct student
{
char name[10];
struct date dob;
}student1;
16.What are storage classes?
Storage classes tell the compiler where to store a variable, how to store a variable, what is the initial value of the
variable and life time of the variable.
Syntax

storage-class data-type variable-name;

There are 4 types : Automatic , Static , External and Register


17.What is meant by scope of a variable?
The scope of a variable determines the area of a variable is actually available for use.
The visibility refers to the accessibility of a variable from memory.
The variables can be classified depending on the place of their declaration.
18. Compare local variables and global variables.
1.Local variables :
Local variables are declared inside a particular function or block of the program.
The local variables can be accessed within the block or function.
2.Global variables :
Global variables are declared outside of all functions including main( ) function.
The global variables can be accessed by all the user defined functions including main( ) function.
19.What are preprocessor directives?
Commands used in are called preprocessor directives and they begin with # symbol and do not end with ;

20

Example:

# define,
# include

20. What are the types of preprocessor directives?


1. File Inclusion
2. Macro Substitution
3. Conditional Inclusion

21

S-ar putea să vă placă și