Professional Documents
Culture Documents
com)
Appendix
Q. What is Compiler ?
JAVA 1991
Prof.Manoj S. Kavedia (9860174297)(urallalone@yahoo.com)
Q.Define variable
Ans.It is an entity that may vary during the program is executing. Variable
is the name given to the location of the memory. This location can contain
integer, real or character constants.
Q.Define Operator
Ans.Operators are the special symbol use to perform special operation (for
example, arithmetic & logical) on operands. Operands are the variables,
constants or expressions on which operators perform operation.
x = 45;
y = 22;
(y>25) ? x = y : x = 50;
| Binary Bitwise OR
^ Bitwise EX-OR
Welcome to C
In order to print the values of the variables printf can also be used as:
Here the %d is called as integer format specifier and used to print the
integer value of variable on the screen.
Syntax:
scanf(“<format string>”, <variables-list>);
Here, the format string will contain the format specifiers or format codes
to accept the values of variables in the sequence of format specifiers.
For example:
int var1;
float var2;
scanf(“%d%f”, &var1, &var2);
This statement will read an integer number and a float number from
keyboard and store these values in var1 and var2 respectively. The
scanf allows all the above format specifiers to use for inputting the
values.
-1-
Q.List Decision Making Statements
Ans. The decision control structure in C can be implemented using:
a) The if statement
b) The if - else statement
c) Nested if – else
d) The else – if ladder
if(condition)
{
//statements1
}
else
{
//statements2
}
Q.List syntax of Nested if-else statement
Ans. Nested if – else
// Statements-default;
// Statements-X;
switch(variable)
{
case value-1:
//statements1;
break;
case value-2:
//statements2;
break;
case value-3:
//statements3;
break;
default:
// default – statements;
}
statement-x;
In the above given syntax, value-1, value-2, value-3…. are the set the
constants. When the value of the variable given in the switch brackets is
matched with any one of these values, the particular set of statements are
executed and then program control transfers out of the switch block. For
example, if value of variable is matched with ‘value-2’ then statements2 are
executed and the break statement transfers the program control out of the
switch. If the match is not found, the ‘default’ block is executed. Remember,
statements-x are executed in any case.
The ‘for loop is an entry controlled loop structure which provides more
concise loop structure having following general form:
Ans.
Nesting of the loop statements is allowed in C programming language.
That is, we can write a ‘for’ loop inside another ‘for’ loop or any other loop in
another loop statement. It can be written as follows:
......
}
ta
le
][4
The
first
dime
nsio
n5
is
num
ber
of
rows
and
num
ber
of
colu
mns.
In
order
The ‘data-type’ specifies type of the array. That is, int, char, float etc. to
The ‘variable-name’ is the name given to the array, by which we will refer it. creat
Finally, size is the maximum number of elements that an array can hold. e
For example: such
two
int var[10]; dime
nsio
This declares the array ‘var’ containing 10 different integer elements. nal
We can store 10 integer constants in the variable ‘var’. array
s in
Q.Define Two dimensional arrays C,
Ans.It is also called as array of arrays. Many times it is required to follo
manipulate the data in table format or in matrix format which contains wing
rows synt
and columns. In these cases, we have to give two dimensions to the array. ax
should be followed.
datatype arrayname[rows][columns];
For example:
int table[5][4];
second dimension 4 is
Q.Define Strings
Ans. The string is sequence of characters that is treated as a single data
item. In general, the character array is called as string. Any group of
characters defined between double quotation marks is a string constant.
Such as –
“The C Programming Language.”
Here
, string_name is the valid variable namname given to the string and
‘size’ determines the number of characters in the string. For example:
char city[10];
char name[30];
Q.Ho
w
Strin
g is
Initi
alize
d
Ans.L
ike
numerical
arrays the
strings can
also be
initialized when they
are declared which is referred as compile time initialization. It can be done
in following three forms:
2. strcat()
This function joins two strings together. That is, this function is used to
concatenate the strings.
4. strcpy()
This function almost works like string-assignment operator. That
is, strcpy() function is used to copy contents of one string into another.
4. strcmp()
This function is used to compare two strings and accordingly
returns the value. That is, it returns the numerical difference between
the strings.
5. strrev()
Q.Define Recursion
Ans.It is a special case of calling a function when a function calls itself
again and again. It forms a chaining of calling a function. For example:
void main(void)
{
printf(“\nHello”);
Main main(); /* recursive call */
Q.What is Structure
Ans.It is a derived data-type in C, which is a collection of different data-
type elements. It is a convenient tool for handling a group of logically related
data items. Structure helps to organize the complex data in more meaningful
way.
struct tag_name
{
data_type variable1;
data_type variable1;
- - - - -;
- - - - -;
};
struct book
{
char title[20];
char author[15];
int pages;
float price;
};
struct book book1, book2, book3;
struct book
{
char title[20];
char author[15];
int pages;
float price;
}book book1, book2, book3;
struct
{
char title[20];
char author[15];
int pages;
float price;
}book book1, book2, book3;
data-type *variable-name;
int *p;
float *x;
int *p;
int x = 10;
p = &x;
M u M b a i \0 \0 \0 \0
M u M b a i \0
int *a[10];
here, the array of pointers will be created i.e. the array will point to 10
different integers, such as:
a[0]=&x;
a[1]=&y;
a[2]=&z;
.
.
.