C - Programme by Real
C - Programme by Real
h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with
a size of 5 and it is initialized to
a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .
Step 2: int i, j, m; The variable i,j,m are declared as an integer type.
Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2
Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.
Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means
2++ so i=3)
Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the variables i, j, m
Hence the output of the program is 3, 2, 15
First understand the logic of post and pre increment.....if ++x means x is incremented by 1 and gets
stored in X.
Let
x=1
y=++x and
y=x++
in first case y will be 2 and x will be 2.(that is X is incremented first and then stored in y)
in second case y will be 1 and x will be 2.(that is x is stored in y and the incremented)
try to understand this logic first..........
Similarly,
in the stmt , i = ++a[1];
since a[1]=1, then after execution of the above stmt,
i will be 2,a[1] will be 2
similarly,
in the stmt , j = a[1]++;
since a[2]=2 now(after execution of I stmt,)
j ll be 2 (post increment will happen) and a[2] will be 3 now..
in the 5th case,
m = a[i++], i is post incremented... so a[i] will be a[2] and i will be 3... so m=a[2]=15
his set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Array and Array
Operations”.
Answer: b
Explanation: Array contains elements only of the same type.
b) int arr[];
View Answer
Answer: c
a) int[] arr;
b) int arr[[]];
c) int[][]arr;
d) int[[]] arr;
View Answer
Answer: c
Explanation: The syntax to declare multidimensional array in java is either int[][] arr; or int arr[][];
7. When does the Array Index Out Of Bounds Exception occur?
a) Compile-time
b) Run-time
c) Not an error
Answer: b
a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality
View Answer
Answer: d
Explanation: Whenever a particular memory location is referred, it is likely that the locations nearby are
also referred, arrays are stored as contigous blocks in memory, so if you want to access array elements,
spatial locality makes it to access quickly.
a) 15
b) 19
c) 11
d) 60
Answer: d
Explanation: Since there are 15 int elements and each int is of 4bytes, we get 15*4 = 60bytes.
1.
A. PL/1
B. FORTRAN
C. BASIC
D. PASCAL
Answer: Option D
Explanation:
The tracks on a disk which can be accessed without repositioning the R/W heads is
A. Surface
B. Cylinder
C. Cluster
A. -1
B. 1
C. 0
D. Yes
Answer: Option C
Explanation:
if s1 == s2 returns 0
10. Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual stack algorithm to
convert the expression from infix to postfix notation.
The maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of
this expression?
a) 1
b) 2
c) 3
d) 4
View Answer
Answer: d
Explanation: When we perform the conversion from infix to postfix expression +, *, (, * symbols are
placed inside the stack. A maximum of 4 symbols are identified during the entire conversion.
a) Predefined size
c) Faster Access
d) All of the mentioned
Answer: d
6. Which of the following operation is possible using a pointer char? (Assuming the declaration is char
*a;)
a) Input via %s
View Answer
Answer: c
Explanation: None.
a) 31
b) 63
c) 12
d) 14
View Answer
Answer: b
Explanation: ISO C99 compiler may consider only first 63 characters for internal names.
a) int __a3;
b) int __3a;
c) int __A3;
View Answer
Answer: d
Explanation: None.
a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
View Answer
Answer: a
Explanation: None.
7. Variable name resolution (number of significant characters for the uniqueness of variable) depends
on ___________
c) C language
View Answer
Answer: a
Explanation: It depends on the standard to which compiler and linkers are adhering.
a) int number;
b) float rate;
c) int variable_count;
d) int $main;
View Answer
Answer: d
Explanation: Since only underscore and no other special character is allowed in a variable name, it
results in an error.
a) volatile
b) true
c) friend
d) export
View Answer
Answer: a
#include <stdio.h>
int main()
printf("%d", ThisIsVariablename);
return 0;
Answer: b
Explanation: Variable names ThisIsVariablename and ThisIsVariableName are both distinct as C is case
sensitive.
Output:
$ cc pgm4.c
$ a.out
14
#include <stdio.h>
int main()
int i;
if ((char)a[i] == '5')
printf("%d\n", a[i]);
else
printf("FAIL\n");
Answer: d
Explanation: The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only.
Output:
$ cc pgm1.c
$ a.out
FAIL
FAIL
FAIL
FAIL
FAIL
2. The format identifier ‘%i’ is also used for _____ data type.
a) char
b) int
c) float
d) double
View Answer
Answer: b
Explanation: Both %d and %i can be used as a format identifier for int data type.
View Answer
Answer: d
Explanation: typedef and struct are used to define user-defined data types.
b) Qualifier
View Answer
Answer: c
Explanation: None
4. Which is correct with respect to the size of the data types?
View Answer
Answer: c
Explanation: char has less bytes than int and int has less bytes than double in any system
#include <stdio.h>
int main()
float x = 'a';
printf("%f", x);
return 0;
a) a
c) a.0000000
d) 97.000000
View Answer
Answer: d
Explanation: Since the ASCII value of a is 97, the same is assigned to the float variable and printed.
Output:
$ cc pgm8.c
$ a.out
97.000000
7. Which of the data types has the size that is variable?
a) int
b) struct
c) float
d) double
View Answer
Answer: b
Explanation: Since the size of the structure depends on its fields, it has a variable size.
#include <stdio.h>
int main()
a) PEACH = 3
b) PEACH = 4
c) PEACH = 5
d) PEACH = 6
View Answer
Answer: c
Explanation: In enum, the value of constant is defined to the recent assignment from left.
Output:
$ cc pgm1.c
$ a.out
PEACH = 5
a) Compiler
b) Preprocessor
c) Linker
d) Assembler
View Answer
Answer: a
Explanation: None.
a) Constant variables need not be defined as they are declared and can be defined later
View Answer
Answer: a
Explanation: Since the constant variable has to be declared and defined at the same time, not doing it
results in an error.
2. Which keyword is used to prevent any changes in the variable within a C program?
a) immutable
b) mutable
c) const
d) volatile
View Answer
Answer: c
a) char a[10];
c) char *str;
d) char a;
View Answer
Answer: d
a) True
b) False
View Answer
Answer: b
Explanation: Since the scope of the variable declared within a function is restricted only within that
function, so the above statement is false.
4. Which of the following data type will throw an error on modulus operation(%)?
a) char
b) short
c) int
d) float
View Answer
Answer: d
Explanation: None.
a) True
b) False
View Answer
Answer: a
Explanation: None.
View Answer
Answer: d
Explanation: None.
View Answer
Answer: b
a) int
b) long
c) float
d) double
View Answer
Answer: d
Explanation: None.
View Answer
Answer: b
Explanation: None.
a) Widening conversions
b) Narrowing conversions
View Answer
Answer: c
Explanation: None
7. When do you need to use type-conversions?
View Answer
Answer: d
Explanation: None.
#include <stdio.h>
int main()
int i = 10;
int *p = &i;
printf("%d\n", *p++);
a) 10
b) 11
c) Garbage value
d) Address of i
View Answer
Answer: a
Explanation: None.
Compile time error is any type of error that prevent a java program compile like a syntax
error, a class not found, a bad file name for the defined class, a possible loss of precision
when you are mixing different java data types and so on.
A runtime error means an error which happens, while the program is running. To deal with
this kind of errors java define Exceptions. Exceptions are objects represents an abnormal
condition in the flow of the program. It can be either checked or unchecked.
#include <stdio.h>
void main()
a) returns 1
b) returns 2
c) Varies
View Answer
Answer: d
Explanation: None.
4. What will be the final value of c in the following C statement? (Initial value: c = 2)
c <<= 1;
a) c = 1;
b) c = 2;
c) c = 3;
d) c = 4;
View Answer
Answer: d
Explanation: None.
#include <stdio.h>
int main()
int a = 1, b = 2;
a += b -= a;
a) 1 1
b) 1 2
c) 2 1
d) 2 2
View Answer
Answer: c
Explanation: None.
a) a %= 10;
b) a /= 10;
c) a |= 10;
View Answer
Answer: d
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
void main()
int k = 8;
int m = 7;
printf("%d", z);
a) 7
b) 8
d) 15
View Answer
Answer: a
Explanation: None.
a) exp1
b) exp2
c) exp3
View Answer
Answer: d
Explanation: None.
6. What will be the final value of c in the following C code snippet? (Initial values: a = 1, b = 2, c = 1)
c += (-c) ? a : b;
a) Syntax Error
b) c = 1
c) c = 2
d) c = 3
View Answer
Answer: c
Explanation: None.
a) <=
b) <<
c) ==
d) +=
View Answer
Answer: d
Explanation: None.
7. Which of the following is the correct order of evaluation for the given expression?
a = w % x / y * z;
a) % / * =
b) / * % =
c) = % * /
d) * % / =
View Answer
Answer: a
Explanation: None.
a) func1();
b) func2();
c) func3();
d) Cannot be predicted
View Answer
Answer: d
Explanation: None.
a) &&
b) >>=
c) ?:
d) ->
View Answer
Answer: c
Explanation: None.
Unary operator: are operators that act upon a single operand to produce a new value.
unary minus(-)
increment(++)
decrement(- -)
NOT(!)
Addressof operator(&)
sizeof()
View Answer
Answer: d
Explanation: None.
a) Right to Left
b) Left to Right
c) Random fashion
View Answer
Answer: d
Explanation: None.
a) 5 = a = b = c = d;
b) a = b = c = d = 5;
c) a = b = 5 = c = d;
View Answer
Answer: b
Explanation: None.
View Answer
Answer: c
Explanation: None.
**Associativity: It defines the order in which operators of the same precedence are evaluated
in an expression. Associativity can be either from left to right or right to left. ... In C, each
operator has a fixed priority or precedence in relation to other operators.
a) !=
b) &&
c) ?:
d) ,
View Answer
Answer: d
Explanation: None.
**Must know:
Here, operators with the highest precedence appear at the top of the table, those with
the lowest appear at the bottom. Within an expression, higher precedence operators will
be evaluated first.
Category Operator Associativity
#include <stdio.h>
void main()
int x = 5;
if (true);
printf("hello");
d) Compiler dependent
View Answer
Answer: b
Explanation: None.
#include <stdio.h>
void main()
int x = 0;
if (x == 0)
printf("hi");
else
printf("hello");
a) hi
c) hello
d) hihello
#include <stdio.h>
void main()
int x = 5;
printf("Hello");
a) Nothing
c) Hello
d) Varies
View Answer
Answer: c
a) if (if (a == 1)){}
b) if (func1 (a)){}
c) if (a){}
d) if ((char) a){}
View Answer
Answer: a
Explanation: None.
a) break
b) return
c) exit
View Answer
Answer: b
Explanation: None.
5. Which keyword is used to come out of a loop only for that iteration?
a) break
b) continue
c) return
View Answer
Answer: b
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
void main()
int i = 0, j = 0;
if (i > 1)
break;
printf("Hi \n");
a) Hi is printed 5 times
b) Hi is printed 9 times
c) Hi is printed 7 times
d) Hi is printed 4 times
View Answer
Answer: a
Explanation: None.
The continue statement in C programming works somewhat like the break statement.
Instead of forcing termination, it forces the next iteration of the loop to take place,
skipping any code in between.
For the for loop, continue statement causes the conditional test and increment portions
of the loop to execute. For the while and do...while loops, continue statement causes
the program control to pass to the conditional tests.
The break statement in C programming has the following two usages − When
a break statement is encountered inside a loop, the loop is immediately terminated and
the program control resumes at the next statement following the loop. It can be used to
terminate a case in the switch statement (covered in the next chapter).
a) a *= b + 1;
b) (c = a * b)!=(a = c + a);
c) a = (b + 1)* a;
View Answer
Answer: d
Explanation: None.
IndiaBIX.Com
Search...
MenuHomeAptitudeLogicalVerbalCurrent AffairsGKEngineeringInterviewOnline
TestsPuzzles
1.
Every time attribute A appears, it is matched with the same value of attribute B, but not
the same value of attribute C. Therefore, it is true that:
A. A → B.
B. A → C.
C. A → (B,C).
D. (B,C) → A.
Answer: Option A
This set of Data Structure Interview Questions and Answers focuses on “Stack
Operations – 2”.
b) AB + CD* E – F **G /
c) AB + CD* E – *F *G /
d) AB + CDE * – * F *G /
View Answer
Answer: c
(AB+CD*E-*F) / G
a) *AB/CD+
b) AB*CD/+
c) A*BC+/D
d) ABCD+/*
View Answer
Answer: b
AB*+(C/D)
a) Branch
b) Tree
c) Queue
d) Stack
View Answer
Answer: d
Explanation: The Stack data structure is used to convert infix expression to postfix
expression. The purpose of stack is to reverse the order of the operators in the
expression. It also serves as a storage structure, as no operator can be printed until both
of its operands have appeared.
a) -/*^ACBDE
b) -ABCD*^DE
c) -A/B*C^DE
d) -A/BC*^DE
View Answer
Answer: c
(-A/B)(C*D^E)
a) 600
b) 350
c) 650
d) 588
View Answer
Answer: b
Explanation: The postfix expression is evaluated using stack. We will get the infix expression as
(5*(10))*(4+3)
= 50*7
= 350.
a) Reversing a string
c) Implementation of recursion
d) Job scheduling
View Answer
Answer: d
a) Infix Expression
b) Prefix Expression
c) Postfix Expression
View Answer
Answer: c
Explanation: The expression in which operator succeeds its operands is called postfix expression. The
expression in which operator precedes the operands is called prefix expression. If an operator is present
between two operands, then it is called infix expressions.
9. If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one at a time, what is the
order of removal?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
View Answer
Answer: b
Explanation: Stack follows LIFO(Last In First Out). So the removal order of elements are DCBA.
2. The data structure required for Breadth First Traversal on a graph is?
a) Stack
b) Array
c) Queue
d) Tree
View Answer
Answer: c
Explanation: In Breadth First Search Traversal, BFS, starting vertex is first taken and adjacent vertices
which are unvisited are also taken. Again, the first vertex which was added as an unvisited adjacent
vertex list will be considered to add further unvisited vertices of the graph. To get first unvisited vertex
we need to follows First In First Out principle. Queue uses FIFO principle.
5. What would be the asymptotic time complexity to insert an element at the front of the linked list
(head is known)?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
View Answer
Answer: b
Explanation: To add an element at the front of the linked list, we will create a new node which holds the
data to be added to the linked list and pointer which points to head position in the linked list. The entire
thing happens within O (1) time. Thus the asymptotic time complexity is O (1).