Zoho - Aptitude
Zoho - Aptitude
Zoho - Aptitude
Model 1
Answer: 2
Solution:
For a number to be a perfect square, it should end with either 0,1,4,5,6 or 9. So all
other options other than (2) are ruled out. Ans. (2)
2. Meena is 24 years old today. Eight years ago, Anju was half the age of Meena.
How is Anju today?
(1) 20 years
(2) 18 years
(3) 16 years
(4) 14 years
Answer: 3
Solution:
Eight years ago Meena must be 16 years old (24 – 8 = 16).
Thus, eight years ago, Anju must be eight years old. (16 / 2 =8).
Thus, Anju must be 16 years old today.(8+8=16). Ans. (3)
3. Rs 720 are to be distributed among A, B and C that half of A’s share is equal to
1/3rd of B’s share which is equal to 1/4th of C’s share. How much is the share of
C?
4. A and B set out to meet each other from two places 165 km apart. A travels 15
km the first day, 14 km the second, 13 km the third and so on. B travels 10 km the
first day, 12 km the second, 14 km the third and so on. When will they meet?
5. The following bar diagram shows the monthly expenditure of living in two
cities Delhi and Bombay on food, security, education, fuel, sanitation and
miscellaneous (in percentage). Study the graph carefully and answer the
following questions.
Image
What fraction of the total expenditure is spent on education in Delhi?
6. The following bar diagram shows the monthly expenditure of living in two
cities Delhi and Bombay on food, security, education, fuel, sanitation and
miscellaneous (in percentage). Study the graph carefully and answer the
following questions.
Image
If the total monthly expenditure to live in Bombay is Rs.10,000, then money spent
on security is
(1) Rs.200
(2) Rs.600
(3) Rs.2000
(4) Rs.6000
Answer: 3
Solution: In Bombay 20% of total expenditure are spent for security
Therefore 20% of Rs.10,000 = Rs.2000
7. The following bar diagram shows the monthly expenditure of living in two
cities Delhi and Bombay on food, security, education, fuel, sanitation and
miscellaneous (in percentage). Study the graph carefully and answer the
following questions.
Image
If the total annual expenditure to live in Delhi is Rs.30,000, then money spent on
food, security and sanitation is
(1) Rs.18500
(2) Rs.18000
(3) Rs.21000
(4) Rs.15000
Answer: 2
Solution: In Delhi percentage of money spent on food, security and sanitation =
30+15+15 = 60%
60% of total expenditure = 30,000*60/100 = Rs.18,000
Only 1 follows.
9. Taken “All men are perishable, All students are perishable” for granted, which
of the following conclusions comes out to be logical?
10. Samir started from his Police Station on inspection duty. After travelling
straight a distance of 4 km he turned left for the market and travelled straight for
600 m. He now turned left again and travelled straight another 200 m, and turned
left and travelled straight 600 m. How far is Samir from the Police Station?
11. A watch reads 4.30. If the minute hand points East, in what direction will the
hour hand point?
(1) South-East
(2) North-East
(3) North
(4) North-west
Answer: 2
Solution: Image
When the minute hand points in East, hour hand points in the north-east
direction.
12. Given an input, a coding machine generates pass codes for six batches
everyday as follows:
Input: you should know about type of questions
Passcodes:
Batch I: you questions should of know type about.
Batch II: about you type questions know should of.
Batch III: about of you should type know questions.
And so till the sixth batch.
The first batch begins at 10.00 am. Each batch works for an hour. There is a rest
period of one hour after the fourth batch’s work is over.
Now answer the following.
If the input on a day is “eight friends are sitting in the circle”, then what will be
the passcode for the batch at 3.00pm?
13. A person starts multiplying consecutive positive integers from 40. How many
numbers should he multiply before the will have result that will end with 4
zeroes?
Answer: 3
Solution: 40 has a zero in it. 45 multiplied by an even number will lead to another
zero and 50 multiplied by an even number will lead to two more zeros. One has to
multiply numbers from 40 through 50. Hence 11 numbers.
Answer: 1
15. Study the flow chart given below and answer the question.
Image
(1) 19 (2) 15 (3) 11 (4) 14
Answer: 4
Solution:
Instruction 1 : 5 [Box 4] + 2 [Box 10] = 3 [Box 1]
Instruction 2 : 3 [Box 1] + 3 [Box 6] = 6 [Box 1]
Instruction 3 : IS 6 [Box 1] evenly divisible by 4? = NO
Instruction 4 : 6 [Box No.] + 3[Box 6] = 9 [Box No.]
Instruction 5 : IS 13 [Box 2] > 9[Box No.] ? = YES
Instruction 6 : 7[Box 9] - 1 = 6 [Box 9]
Instruction 2 : 6 [Box 1] + 6 [Box 9] = 12 [Box 1]
Instruction 3 : IS 12 [Box 1] evenly divisible by 4? = NO
Instruction 4 : 9[Box No.] + 3[Box 6] = 12[Box No.]
Instruction 5 : IS 13 [Box 2] > 12 [Box No.] ? = YES
Instruction 6 : 6 [Box 9] -1 = 5 [Box 9]
Instruction 2 : 12 [Box 1] + 2 {Box 12] =14[Box 1]
Instruction 3 : IS 14 [Box 1] evenly divisible by 4? = NO
Instruction 4 : 12 [Box No.] + 3 [Box 6] = 15 [Box No.]
Instruction 5 : IS 13 [Box 2] > 15 [Box No.] ? = NO
ANSWER Box 1 = 14
1. #include <stdio.h>
2. void main()
3. {
4. int x = 97;
5. int y = sizeof(x++);
6. printf("X is %d", x);
7. }
(1) X is 97
(2) X is 98
(3) X is 99
(4) Run time error
Answer: 1
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1;
5. switch (a)
6. {
7. case a:
8. printf("Case A ");
9. default:
10. printf("Default");
11. }
12. }
1. #include <stdio.h>
2. int main()
3. {
4. printf("%d ", 1);
5. goto l1;
6. printf("%d ", 2);
7. }
8. void foo()
9. {
10. l1: printf("3 ", 3);
11. }
(1) 123
(2) 13
(3) 1 3 2
(4) Compile time error
Answer: 4
#include <stdio.h>
int main()
{
int i = 10;
void *p = &i;
printf("%d\n", (int)*p);
return 0;
}
#include <stdio.h>
void foo(float *);
int main()
{
int i = 10, *p = &i;
foo(&i);
}
void foo(float *p)
{
printf("%f\n", *p);
}
(1) 10.000000
(2) 0.000000
(3) Compile time error
(4) Undefined behaviour
Answer: 2
#include <stdio.h>
void f(int (*x)(int));
int myfoo(int i);
int (*foo)(int) = myfoo;
int main()
{
f(foo(10));
}
void f(int (*i)(int))
{
i(11);
}
int myfoo(int i)
{
printf("%d\n", i);
return i;
}
(1) true
(2) false
(3) Depends on the standard
(4) Depends on the compiler
Answer: 2
(1) frexp(x);
(2) atan2(x,y);
(3) srand(x);
(4) fmod(x);
Answer: 4
28.Relational calculus is a
(1) Procedural language.
(2) Non Procedural language.
(3) Data definition language.
(4) High-level language
Answer: 2
Model 2
1. Two trains are travelling on parallel tracks in the same direction, at speed of 50
km/hr and 32 km/hr respectively. The faster train crosses the last boggy of the
slower train, measuring 18 m in 18 seconds. The length of the faster train is
(1) 144 m
(2) 0.072 km
(3) 720 m
(4) 1.44 km
Answer: 2
Solution:
Let the length of faster train be Xm => relative speed = 50 – 32 = 18km/hr,
Distance = (X + 18) m, Time = 18 sec => Speed = Distance / Time
=> 18 x 5/18 = (X + 18)/18 => X = 72 m = 0.072km. Ans. (2)
2. An Arab buys two horses, paying Rs. 5000 less for one than for the other. He
sells the dearer one at 20% gain and the cheaper one at 30% gain. If he gets Rs.
4000 less on the first than on the second, then the cost price of the second horse
is
3. A jeep travels a distance of 100 km at a uniform speed. If the speed of the jeep
is 5 kmph more, then it takes 1 hour less to cover the same distance. The original
speed of the jeep is
(1) 20 kmph
(2) 25 kmph
(3) 30 kmph
(4) 50 kmph
Answer: 1
Solution:
Let the original speed of the jeep be x kmph. => (100/X) – (100/(X+5)) = 1.
Solving this, we get x = 20 kmph. Ans. (1)
4. A trader purchases some glass jars for Rs.1400. Five of them were broken. If he
sold remaining at Rs.10 more than cost price, he got a profit of Rs.175. What was
cost price of one jar.
(1) Rs.20
(2) Rs.35
(3) Rs.45
(4) Rs.70
Answer: 2
Solution: Let us assume number of jars = x and cost of a jar = y
Given xy = 1400
(x-5)(y+10)=1575
x=1400/y
sub x in the equation
y2+45y-2800 = 0
x = -80 or 35
Therefore x=35
5. A tin of oil was 4/5 full. When six bottles of oil were taken out and four bottles
of oil were poured in, it was 3/4 full. How many bottles of oil does the tin contain
initially?
(1) 16
(2) 40
(3) 32
(4) None of these
Answer: 3
Solution: Two bottles fill (4/5)-(3/4) = (1/20) of the tin.
(4/5)of the tin will be filled by 32 bottles.
7. The following line graphs show the data of company. The left line graph shows
the sales and cost which is in Rs. lakhs and the right line graph shows the number
of employees (in thousands). Refer to the graphs to answer the questions that
follow.
Image
Profit = Sales – Cost
Image
(1) January
(2) March
(3) September
(4) November
Answer: 3
Solution:
Profit = Sales - Cost.
In September, the profit is Rs.4 Lakhs and it is the highest.
8. The following line graphs show the data of company. The left line graph shows
the sales and cost which is in Rs. lakhs and the right line graph shows the number
of employees (in thousands). Refer to the graphs to answer the questions that
follow.
Image
Assuming that no employee left the job, how many more people did the company
take on in the given period?
(1) 2000 (2) 3000 (3) 4000 (4) 5000
Answer: 4
Solution:
Number of employees in January is 11000 and the number in November is 16000.
Hence 5000 more people were taken in by the company.
9. The following line graphs show the data of company. The left line graph shows
the sales and cost which is in Rs. lakhs and the right line graph shows the number
of employees (in thousands). Refer to the graphs to answer the questions that
follow.
Image
(1) January
(2) May
(3) September
(4) November
Answer: 2
Solution:
Here we have to approximate the ratio of profit to the number of employees. It is
lowest in May.
Which of the following could be the combination of songs to be played on the first
day of a month?
(1) P, R, V, S, U
(2) Q, S, R, V, U
(3) T, U, R, V, S
(4) U, Q, S, T, W
Answer: 3
Solution: Option 1: Not possible as P and V cannot be played on the same day
Option 2: Not possible as T has to be played if Q is played
Option 3: Possible as all conditions are satisfied.
Option 4: Not possible as the last song is not S or U
If the songs “R” and “W” are to be played on the first day, which of the following
could be the other songs to be played on that day?
(1) P, T, U
(2) Q, S, V
(3) T, S, V
(4) Q, T, V
Answer: 3
Solution: Option 1: Not possible as V should be played when R is played
Option 2: Not possible as T has to be played if Q is played
Option 3: Possible as all conditions are satisfied.
Option 4: Not possible as neither S nor U is present.
If song “R” is played at third place in a sequence, which of the following cannot be
the second song to be played in that sequence?
14. The sides of a cube show the colours of rainbow. Two positions of the cube of
shown below. Which of the colours of rainbow is left out?
Image
(1) Indigo
(2) green
(3) violet
(4) yellow
Answer: 3
Solution:
Ans:[c]
The colours of rainbow are VIBGYOR
15. Lou, Moe, and Ned were at the Heave Health Club on the same day this month;
it was there and then that they met.
[1] Lou, Moe, and Ned each began going to the health club last month.
[2] One of them goes every 2 days, another one goes every 3 days, and the
remaining one goes every 7 days.
[3] Lou went to the health club for the first time this month on a Monday, Moe
went to the health club for the first time this month on a Wednesday, and Ned
went to the health club for the first time this month on a Friday.
On which day of this month did Lou, Moe, and Ned meet?
(1) a = 5
(2) a = 10
(3) Compilation error
(4) Runtime error
Answer: 3
Solution: The #define substitutes a with 10 leaving no identifier and hence
compilation error.
Output:
$ cc pgm3.c
pgm3.c: In function ‘main’:
pgm3.c:5: error: expected identifier or ‘(’ before numeric constant
(1) 1
(2) 2
(3) Compile time error
(4) Undefined behaviour
Answer: 1
19.Example of iteration in C.
(1) for
(2) while
(3) do-while
(4) All of the mentioned
Answer: 4
1. #include <stdio.h>
2. int foo(int, int);
3. #define foo(x, y) x / y + x
4. int main()
5. {
6. int i = -6, j = 3;
7. printf("%d ",foo(i + j, 3));
8. #undef foo
9. printf("%d\n",foo(i + j, 3));
10. }
11. int foo(int x, int y)
12. {
13. return x / y + x;
14. }
(1) -8 -4
(2) Compile time error
(3) -8 -8
(4) Undefined behaviour
Answer: 1
#include <stdio.h>
void foo(int*);
int main()
{
int i = 10, *p = &i;
foo(p++);
}
void foo(int *p)
{
printf("%d\n", *p);
}
(1) 10
(2) Some garbage value
(3) Compile time error
(4) Segmentation fault
Answer: 1
#include <stdio.h>
int main()
{
const int ary[4] = {1, 2, 3, 4};
int *p;
p = ary + 3;
*p = 5;
printf("%d\n", ary[3]);
}
(1) 4
(2) 5
(3) Compile time error
(4) 3
Answer: 2
#include <stdio.h>
void main()
{
char *s= "hello";
char *p = s + 2;
printf("%c\t%c", *p, s[1]);
}
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}
(1) 5
(2) Run time error
(3) 6
(4) Junk
Answer: 3
25. Which of the given option is the correct method for initialization?
typedef char *string;
28. For binary files, a _-----_ must be appended to the mode string.
(1) Nothing
(2) “b”
(3) “binary”
(4) “01″
Answer: 2
Model 3
1. The questions given below have four options of three statements each. Read
the statements in each option carefully and identify the option where the third
statement logically follows the first two statements in the option.
(1) All seconds are hours.
Some minutes are not hours.
Some minutes are not seconds.
(2) All atoms are particles.
Some particles are not protons.
Some atoms are not protons.
(3) All houses are buildings.
No house is an office.
No building is an office.
(4) No solid is liquid.
No solid is a gas.
No liquid is gas.
2. The questions given below have four options of three statements each. Read
the statements in each option carefully and identify the option where the third
statement logically follows the first two statements in the option.
3. The questions given below have four options of three statements each. Read
the statements in each option carefully and identify the option where the third
statement logically follows the first two statements in the option.
4. The questions given below have four options of three statements each. Read
the statements in each option carefully and identify the option where the third
statement logically follows the first two statements in the option.
6. These are based on the following statements. Changes are ideas. No idea is a
fancy. Most fancies are images.
1984 4000 80
1985 5700 65
1986 11800 15
1987 14100 25
1988 16000 30
Image
After 1988, if the total sales turnover increases every year by the same amount as
the average increase from 1984 to 1988, and price level increases by 20% over
the previous year, then how many units will be sold in 1990?
(1) 11700
(2) 13000
(3) 15700
(4) 17700
Answer: 2
Solution:
Sales turnover in 1988 = Rs.48 crore (from Q.35)
Sales turnover in 1984 = Rs.32 crore.
Average annual increase in sales turnover = Rs.16/4 = Rs.4 crore,
=> Sales turnover in 1990 = Rs.(48 + 2x4) = Rs.56 crore.
Also price of a computer in 1990 = Rs.30000 (1 + 20/100)2 = Rs.43200
Units sold in 1990 = (56 crore/43200) = Rs. 13000 nearly.
200 200 200 200 200 200 2000 200 200 2003 200 200
0 1 2 3 4 5 1 2 4 5
1 ENRON 6.5 5.2 8 10.7 11.6 5.19 20.5 21.4 21.7 26.8 27 23.8
2 HORISTEN 2.9 3.5 2.4 3.5 1.7 4.33 34.2 33.2 30.9 38.87 40.7 35.8
2
3 CALLONA 4.9 3.1 6 11.2 9.1 3.85 25.4 25.4 18.2 29.82 30.9 25.1
4
4 JOSEPH 9.9 9.9 1.5 4.5 2.8 3.62 19.5 31.3 24.9 19.67 19.4 15
5 PREMIER 3 5.4 4.1 10.3 35 6.91 51.2 50.3 40.7 48.12 47 36.4
6 BRIDGESTONE 5.6 4 5.4 6.7 2.8 6.87 34.9 34.7 21.9 27.59 23.9 18.2
7 TENON 1.4 1.4 1.3 5.8 4.2 3.13 22.7 23.9 18.2 27.35 29 25.2
8 VERDE 6.5 6.1 8.9 13.8 11.9 5.98 31.4 30.3 30 36.38 38 26.1
9 KALCI 6 5.5 5.4 6.9 7.3 3.95 59.3 60.7 35.3 38.57 29.4 24
10 MALVIN 15.1 9.8 13.5 21.1 29.7 8.91 49.2 50.8 22.1 50.43 51.1 34.8
11 DC 8.4 8.3 7.2 13.7 15.2 7.7 45.5 61.7 36.7 48.86 52.5 33.2
12 WINSIN 10.3 6.8 6.8 11.6 12.7 4.95 45.7 44.7 33.1 38.16 37.6 31.2
13 ZKIN 8 4.5 12.7 14.5 9 4.87 46.2 57.8 28.3 40.98 40.6 35.8
14 STAR 6.8 6.2 12.4 18.8 28 9.88 54.2 54.9 50.6 59.98 56.7 50.9
15 HINDALCO 6.3 5.9 8.5 14.3 19 6.33 55.3 49.8 35.2 41.88 41.1 35.9
16 CAMCON 8.4 6.6 7.8 13.3 12.4 5.98 43.1 46 31.8 39.6 40.1 33.1
17 TORA 4.5 3.6 4 7.1 5.6 3.82 19.2 18.8 14.7 18.1 18.1 15.4
18 UKAI 5.1 4.4 6.5 6.3 5.5 3.66 13.6 11.6 12.4 13.12 13.7 12.4
(1) HIDALCO
(2) ZKIN
(3) CAMCON
(4) None of these
Answer: 3
Solution:
Institutes
2003 Rank 2003 Rank
1. ENRON 10.7 10 26.8 15
2. HORISTEN 3.5 18 38.87 8
3. CALLONA 11.2 9 29.82 12
4 .JOSEPH 4.5 17 19.67 16
5 .PREMIER 10.3 11 48.12 4
6 .BRIDGESTONE 6.7 14 27.59 13
7. TENON 5.8 16 27.35 14
8. VERDE 13.8 5 36.38 11
9. KALCI 6.9 13 38.57 9
10. MALVIN 21.1 1 50.43 2
11. DC 13.7 6 48.86 3
12 .WINSIN 11.6 8 38.16 10
13. ZKIN 14.5 3 40.98 6
14. STAR 18.8 2 59.98 1
15 .HINDALCO 14.3 4 41.88 5
16 .CAMCON 13.3 7 39.6 7
17 .TORA7.1 12 18.1 17
18. UKAI 6.3 15 13.12 18
From the table we can find that after arranging in descending order we will get
same Rank for CAMCON which is at 7th rank both way.
200 200 200 200 200 200 2000200 200 2003 200 200
0 1 2 3 4 5 1 2 4 5
1 ENRON 6.5 5.2 8 10.7 11.6 5.19 20.5 21.4 21.7 26.8 27 23.8
2 HORISTEN 2.9 3.5 2.4 3.5 1.7 4.33 34.2 33.2 30.9 38.87 40.7 35.8
2
3 CALLONA 4.9 3.1 6 11.2 9.1 3.85 25.4 25.4 18.2 29.82 30.9 25.1
4
4 JOSEPH 9.9 9.9 1.5 4.5 2.8 3.62 19.5 31.3 24.9 19.67 19.4 15
5 PREMIER 3 5.4 4.1 10.3 35 6.91 51.2 50.3 40.7 48.12 47 36.4
6 BRIDGESTONE 5.6 4 5.4 6.7 2.8 6.87 34.9 34.7 21.9 27.59 23.9 18.2
7 TENON 1.4 1.4 1.3 5.8 4.2 3.13 22.7 23.9 18.2 27.35 29 25.2
8 VERDE 6.5 6.1 8.9 13.8 11.9 5.98 31.4 30.3 30 36.38 38 26.1
9 KALCI 6 5.5 5.4 6.9 7.3 3.95 59.3 60.7 35.3 38.57 29.4 24
10 MALVIN 15.1 9.8 13.5 21.1 29.7 8.91 49.2 50.8 22.1 50.43 51.1 34.8
11 DC 8.4 8.3 7.2 13.7 15.2 7.7 45.5 61.7 36.7 48.86 52.5 33.2
12 WINSIN 10.3 6.8 6.8 11.6 12.7 4.95 45.7 44.7 33.1 38.16 37.6 31.2
13 ZKIN 8 4.5 12.7 14.5 9 4.87 46.2 57.8 28.3 40.98 40.6 35.8
14 STAR 6.8 6.2 12.4 18.8 28 9.88 54.2 54.9 50.6 59.98 56.7 50.9
15 HINDALCO 6.3 5.9 8.5 14.3 19 6.33 55.3 49.8 35.2 41.88 41.1 35.9
16 CAMCON 8.4 6.6 7.8 13.3 12.4 5.98 43.1 46 31.8 39.6 40.1 33.1
17 TORA 4.5 3.6 4 7.1 5.6 3.82 19.2 18.8 14.7 18.1 18.1 15.4
18 UKAI 5.1 4.4 6.5 6.3 5.5 3.66 13.6 11.6 12.4 13.12 13.7 12.4
10.Find the ratio between the LCM and HCF of 5, 15 and 20?
(1) 8 : 1
(2) 14 : 3
(3) 12 : 2
(4) 12 : 1
Answer: 4
Solution:
Image
11. The average of 71 results is 48. If the average of the first 59 results is 46 and
that last 11 is 52. Find the 60th result.
(1) 132 (2) 122 (3) 134 (4) 128
Answer: 2
Solution: 71*48 = 59*46 + x + 11*52 => x = 122
Alternately, this can be solved by using the concepts of surpluses and deficits as:
2*59 (deficit) -* 11 (surplus) + 48 (average to be maintained by the 60 th
number)
= 118-44 + 48 = 122
12. A man covers 1/3rd of his journey by cycle at 50 Km/h, the next 1/3 by car at
30 km/h,, and the rest walking at 7 km/h. Find his average speed during the
whole journey.
13. A man sells an article at 5% above its cost price. If he hand bought it at 5%
less than what he paid for it and sold it for Rs.2 less, he would have gained 10%.
Find the cost price of the article.
(1) Rs.500
(2) Rs.360
(3) Rs.425
(4) Rs.400
Answer: 4
Solution:
Selling price = 1.05 cost price
(.95C.P)*1.1=1.05C.P-2
1.05C.P-1.045C.P=2
C.p = 2/.005 =400
14. What is the simple interest on a sum of Rs.700 if the rate of interest for the
first 3 years is 8% per annum and for the last 2 years is 7.5% per annum?
(1) Rs.269.5
(2) 283
(3) 273
(4) 280
Answer: 3
Solution:
For first three years
PNR/100=700*3*8/100=168
For last two years
PNR/100=700*2*7.5/100=105
Adding both the values S.I.=Rs.273
15. A train moves at a constant speed of 120 km/h for one kilometer and at 40
kmph for the next one kilometer. What is the average speed of the train.
(1) 48kmph
(2) 50kmph
(3) 80kmph
(4) None of these
Answer: 4
Solution:
Image
1. #include <stdio.h>
2. int main()
3. {
4. int a = 1;
5. switch (a)
6. case 1:
7. printf("%d", a);
8. case 2:
9. printf("%d", a);
10. case 3:
11. printf("%d", a);
12. default:
13. printf("%d", a);
14. }
21. Which of the following are correct syntaxes to send an array as a parameter to
function:
(1) func(&array);
(2) func(array);
(3) func(*array);
(4) func(array[size]);
Answer: 1,2
(1) int a = 0, b = 1, c = 2;
int array[3] = {a, b, c};
(2) int size = 3;
int array[size];
(3) int size = 3;
int array[size] = {1, 2, 3};
(4) All of the mentioned
Answer: 3
23. An array of similar data types which themselves are collection of dissimilar
data type are
#include <stdio.h>
int main()
{
char *a[1] = {"hello"};
printf("%s", a[0]);
return 0;
}
(1) typedefs
(2) Function pointer
(3) Both (a) and (b)
(4) None of the mentioned
Answer: 2
(1) Nothing
(2) Compile time error
(3) Junk
(4) 8
Answer: 1
1. How many times in a day, are the hands of a clock in straight line but opposite
in direction?
A. 20
B. 22
C. 24
D. 48
B. 22
3. David started a software business by investing Rs. 50,000. After six months,
Julia joined her with a capital of Rs. 80,000. After 3 years, they earned a profit of
Rs. 24,500. What was David’s share in the profit?
A. Rs. 9,423
B. Rs. 10,250
C. Rs. 12,500
D. Rs. 10,500
D. Rs. 10,500
4. A bag contains 2 red, 3 green and 2 blue balls. Two balls are drawn at random.
What is the probability that none of the balls drawn is blue?
A. 10/21
B. 11/21
C. 2/7
D. 5/7
A. 10/21
5. A boatman goes 2 km against the current of the stream in 1 hour and goes 1 km
along the current in 10 minutes. How long will it take to go 5 km in stationary
water?
A. 40 minutes
B. 1 hour
C. 1 hr 15 min
D. 1 hr 30 min
C. 1 hr 15 min
6. 8 litres are drawn from a cask full of wine and is then filled with water. This
operation is performed three more times. The ratio of the quantity of wine now
left in cask to that of water is 16 : 65. How much wine did the cask hold
originally?
A. 18 litres
B. 24 litres
C. 32 litres
D. 42 litres
B. 24 litres
8. Two goods train each 500 m long, are running in opposite directions on
parallel tracks. Their speeds are 45 km/hr and 30 km/hr respectively. Find the
time taken by the slower train to pass the driver of the faster one.
A. 12 sec
B. 24 sec
C. 48 sec
D. 60 sec
B. 24 sec
9. Two pipes can fill a tank in 20 and 24 minutes respectively and a waste pipe
can empty 3 gallons per minute. All the three pipes working together can fill the
tank in 15 minutes. The capacity of the tank is:
A. 60 gallons
B. 100 gallons
C. 120 gallons
D. 180 gallons
C. 120 gallons
10. A train 240 m long passes a pole in 24 seconds. How long will it take to pass a
platform 650 m long?
A. 65 sec
B. 89 sec
C. 100 sec
D. 150 sec
B. 89 sec
11. A wheel that has 6 cogs is meshed with a larger wheel of 14 cogs. When the
smaller wheel has made 21 revolutions, then the number of revolutions mad by
the larger wheel is:
A. 4
B. 9
C. 12
D. 49
B. 9
12. 10 women can complete a work in 7 days and 10 children take 14 days to
complete the work. How many days will 5 women and 10 children take to
complete the work?
A. 3
B. 5
C. 7
D. Cannot be determined
C. 7
13. Three partners shared the profit in a business in the ratio 5 : 7 : 8. They had
partnered for 14 months, 8 months and 7 months respectively. What was the
ratio of their investments?
A. 5 : 7 : 8
B. 20 : 49 : 64
C. 38 : 28 : 21
D. None of these
B. 20 : 49 : 64
14. A starts business with Rs. 3500 and after 5 months, B joins with A as his
partner. After a year, the profit is divided in the ratio 2 : 3. What is B’s
contribution in the capital?
A. Rs. 7500
B. Rs. 8000
C. Rs. 8500
D. Rs. 9000
D. Rs. 9000
15. The captain of a cricket team of 11 members is 26 years old and the wicket
keeper is 3 years older. If the ages of these two are excluded, the average age of
the remaining players is one year less than the average age of the whole team.
What is the average age of the team?
A.23 years
B.24 years
C.25 years
D.None of these
A.23 years
16. The present ages of three persons in proportions 4 : 7 : 9. Eight years ago, the
sum of their ages was 56. Find their present ages (in years).
A. 8, 20, 28
B. 16, 28, 36
C. 20, 35, 45
D. None of these
B. 16, 28, 36
17. The least number which when divided by 5, 6 , 7 and 8 leaves a remainder 3,
but when divided by 9 leaves no remainder, is:
A. 1677
B. 1683
C. 2523
D. 3363
B. 1683
19. The true discount on a bill due 9 months hence at 16% per annum is Rs. 189.
The amount of the bill is:
A. Rs. 1386
B. Rs. 1764
C. Rs. 1575
D. Rs. 2268
B. Rs. 1764
20. Find the odd man out.
41, 43, 47, 53, 61, 71, 73, 81
A. 61
B. 71
C. 73
D. 81
D. 81
21. From a group of 7 men and 6 women, five persons are to be selected to form a
committee so that at least 3 men are there on the committee. In how many ways
can it be done?
A. 564
B. 645
C. 735
D. 756
D. 756
23. The cost price of a Rs. 100 stock at 4 discount, when brokerage is 1:4% is:
A. Rs. 95.75
B. Rs. 96
C. Rs. 96.25
D. Rs. 104.25
C. Rs. 96.25
24. Direction:
Each question given below consists of a question followed by three statements.
You have to study the question and the statements and decide which of the
statement(s) is/are necessary to answer the question.
What is the principal sum?
I. The sum amounts to Rs. 690 in 3 years at S.I.
II. The sum amounts to Rs. 750 in 5 years at S.I.
III. The rate of interest is 5% p.a.
A.I and III only
B.II and III only
C.I and II only
D.I and III only, or II and III only
E.Any two of the three
E.Any two of the three
25. Direction:
Each of questions given below consists of a question followed by three
statements. You have to study the question and the statements and decide which
of the statement(s) is/are necessary to answer the question.
What is the speed of the boat in still water?
I. The speed downstream is 12 kmph.
II. The speed upstream is 4 kmph.
III. In a to and fro journey between two points, the average speed of the boat was
6 kmph.
A.I and II only
B.All I, II and III
C.III, and either I or II
D.Any two of the three
E.None of these
D.Any two of the three
26. Mr. Thomas invested an amount of Rs. 13,900 divided in two different
schemes A and B at the simple interest rate of 14% p.a. and 11% p.a. respectively.
If the total amount of simple interest earned in 2 years be Rs. 3508, what was the
amount invested in Scheme B?
A. Rs. 6400
B. Rs. 6500
C. Rs. 7200
D. Rs. 7500
A. Rs. 6400
27. The product of two numbers is 9375 and the quotient, when the larger one is
divided by the smaller, is 15. The sum of the numbers is:
A. 380
B. 395
C. 400
D. 425
C. 400
28. Some articles were bought at 6 articles for Rs. 5 and sold at 5 articles for Rs. 6.
Gain percent is:
A. 30%
B. 35%
C. 44%
C. 44%
29. The greatest number of four digits which is divisible by 15, 25, 40 and 75 is:
A. 9000
B. 9400
C. 9600
D. 9800
C. 9600
30. Present ages of John and Dina are in the ratio of 5 : 4 respectively. Three years
hence, the ratio of their ages will become 11 : 9 respectively. What is Dina’s
present age in years?
A.24
B.27
C.40
D.Cannot be determined
A.24
31. If 6th March, 2005 is Monday, what was the day of the week on 6th March,
2004?
A. Sunday
B. Saturday
C. Tuesday
D. Wednesday
A. Sunday
32. Find out the wrong number in the given sequence of numbers.
22, 33, 66, 99, 121, 279, 594
A. 33
B. 121
C. 279
D. 594
C. 279
33. In what ratio must a grocer mix two varieties of pulses costing Rs. 15 and Rs.
20 per kg respectively so as to get a mixture worth Rs. 16.50 kg?
A. 3 : 7
B. 5 : 7
C. 7 : 3
D. 7 : 5
C. 7 : 3
34. Market value of a 10.5% stock, in which an income of Rs. 756 is derived by
investing Rs. 9000, brokerage being 1:4%, is:
A. Rs. 108.25
B. Rs. 112.20
C. Rs. 124.75
D. Rs. 125.25
C. Rs. 124.75
35. A, B and C can do a piece of work in 20, 30 and 60 days respectively. In how
many days can A do the work if he is assisted by B and C on every third day?
A. 12 days
B. 15 days
C. 16 days
D. 18 days
B. 15 days
37. Robert is travelling on his cycle and has calculated to reach point A at 2 P.M. if
he travels at 10 kmph, he will reach there at 12 noon if he travels at 15 kmph. At
what speed must he travel to reach A at 1 P.M.?
A. 8 kmph
B. 11 kmph
C. 12 kmph
D. 14 kmph
C. 12 kmph
38. A man rows to a place 48 km distant and come back in 14 hours. He finds that
he can row 4 km with the stream in the same time as 3 km against the stream.
The rate of the stream is:
A. 1 km/hr
B. 1.5 km/hr
C. 2 km/hr
D. 2.5 km/hr
A. 1 km/hr
39. Six years ago, the ratio of the ages of David and John was 6 : 5. Four years
hence, the ratio of their ages will be 11 : 10. What is John’s age at present?
A. 16 years
B. 18 years
C. 20 years
D. Cannot be determined
A. 16 years
40. A fires 5 shots to B’s 3 but A kills only once in 3 shots while B kills once in 2
shots. When B has missed 27 times, A has killed:
A. 30 birds
B. 60 birds
C. 72 birds
D. 90 birds
A. 30 birds
41. The difference between the length and breadth of a rectangle is 23 m. If its
perimeter is 206 m, then its area is:
A. 1520 m2
B. 2420 m2
C. 2480 m2
D. 2520 m2
D. 2520 m2
42. What was the day of the week on 28th May, 2006?
A.Thursday
B.Friday
C.Saturday
D.Sunday
D.Sunday
43. In how many ways can a group of 5 men and 2 women be made out of a total
of 7 men and 3 women?
A. 63
B. 90
C. 126
D. 45
E. 135
A. 63
44. Find out the wrong number in the given sequence of numbers.
8, 13, 21, 32, 47, 63, 83
A.47
B.63
C.32
D.83
A.47
46. The sum of two number is 25 and their difference is 13. Find their product.
A. 104
B. 114
C. 315
D. 325
B. 114
47. A is two years older than B who is twice as old as C. If the total of the ages of
A, B and C be 27, the how old is B?
A. 7
B. 8
C. 9
D. 10
E. 11
D. 10
48. Speed of a boat in standing water is 9 kmph and the speed of the stream is 1.5
kmph. A man rows to a place at a distance of 105 km and comes back to the
starting point. The total time taken by him is:
A. 16 hours
B. 18 hours
C. 20 hours
D. 24 hours
D. 24 hours
49. A sum fetched a total simple interest of Rs. 4016.25 at the rate of 9 p.c.p.a. in 5
years. What is the sum?
A. Rs. 4462.50
B. Rs. 8032.50
C. Rs. 8900
D. Rs. 8925
E. None of these
D. Rs. 8925
50. A person takes a loan of Rs. 200 at 5% simple interest. He returns Rs. 100 at
the end of 1 year. In order to clear his dues at the end of 2 years, he would pay:
A. Rs. 105
B. Rs. 110
C. Rs. 115
D. Rs. 115.50
C. Rs. 115
51. Find out the wrong number in the given sequence of numbers.
56, 72, 90, 110, 132, 150
A.72
B.110
C.132
D.150
D.150
52. Insert the missing number.
8, 24, 12, 36, 18, 54, (….)
A.27
B.108
C.68
D.72
A.27
53. In a two-digit, if it is known that its unit’s digit exceeds its ten’s digit by 2 and
that the product of the given number and the sum of its digits is equal to 144,
then the number is:
A.24
B.26
C.42
D.46
A.24
54. A man standing at a point P is watching the top of a tower, which makes an
angle of elevation of 30 Degree with the man’s eye. The man walks some distance
towards the tower to watch its top and the angle of the elevation becomes 60
Degree. What is the distance between the base of the tower and the point P?
A. 43 units
B. 8 units
C. 12 units
D. Data inadequate
D. Data inadequate
55. A library has an average of 510 visitors on Sundays and 240 on other days.
The average number of visitors per day in a month of 30 days beginning with a
Sunday is:
A. 250
B. 276
C. 280
D. 285
D. 285
56. The average monthly income of P and Q is Rs. 5050. The average monthly
income of Q and R is Rs. 6250 and the average monthly income of P and R is Rs.
5200. The monthly income of P is:
A. 3500
B. 4000
C. 4050
D. 5000
B. 4000
58. Banker’s discount of a certain sum of money is Rs. 72 and the true discount on
the same sum for the same time is Rs. 60. The sum due is:
A. Rs. 360
B. Rs. 432
C. Rs. 540
D. Rs. 1080
A. Rs. 360
59. A man wants to sell his scooter. There are two offers, one at Rs. 12,000 cash
and the other a credit of Rs. 12,880 to be paid after 8 months, money being at
18% per annum. Which is the better offer?
A. Rs. 12,000 in cash
B. s. 12,880 at credit
C. Both are equally good
D. [NIL]
A. Rs. 12,000 in cash
60. The ratio between the length and the breadth of a rectangular park is 3 : 2. If a
man cycling along the boundary of the park at the speed of 12 km/hr completes
one round in 8 minutes, then the area of the park (in sq. m) is:
A. 15360
B. 153600
C. 30720
D. 307200
B. 153600
61. If log10 2 = 0.3010, the value of log 10 80 is:
A. 1.6020
B. 1.9030
C. 3.9030
D. None of these
B. 1.9030
63. A takes twice as much time as B or thrice as much time as C to finish a piece of
work. Working together, they can finish the work in 2 days. B can do the work
alone in:
A.4 days
B.6 days
C.8 days
D.12 days
B.6 days
65. A trader mixes 26 kg of rice at Rs. 20 per kg with 30 kg of rice of other variety
at Rs. 36 per kg and sells the mixture at Rs. 30 per kg. His profit percent is:
A. No profit, no loss
B. 5%
C. 8%
D. 10%
E. None of these
B. 5%
66. In an election between two candidates, one got 55% of the total valid votes,
20% of the votes were invalid. If the total number of votes was 7500, the number
of valid votes that the other candidate got, was:
A. 2700
B. 2900
C. 3000
D. 3100
A. 2700
67. Julia’s father was 38 years of age when she was born while her mother was 36
years old when her brother four years younger to her was born. What is the
difference between the ages of her parents?
A. 2 years
B. 4 years
C. 6 years
D. 8 years
C. 6 years
68. Find a positive number which when increased by 17 is equal to 60 times the
reciprocal of the number.
A.3
B.10
C.17
D.20
A.3
69. Direction:
Each of the questions given below consists of a question followed by three
statements. You have to study the question and the statements and decide which
of the statement(s) is/are necessary to answer the question.
In a cricket team, the average age of eleven players in 28 years. What is the age of
the captain?
I. The captain is eleven years older than the youngest player.
II. The average age of 10 players, other than the captain is 27.3 years.
III. Leaving aside the captain and the youngest player, the average ages of three
groups of three players each are 25 years, 28 years and 30 years respectively.
A. Any two of the three
B. All I, II and III
C. II only or I and III only
D. II and III only
E. None of these
C. II only or I and III only
70. In a regular week, there are 5 working days and for each day, the working
hours are 8. A man gets Rs. 2.40 per hour for regular work and Rs. 3.20 per hours
for overtime. If he earns Rs. 432 in 4 weeks, then how many hours does he work
for?
A.160
B.175
C.180
D.195
B.175
71. Find out the wrong number in the given sequence of numbers.
582, 605, 588, 611, 634, 617, 600
A.634
B.611
C.605
D.600
A.634
72. Find out the wrong number in the given sequence of numbers.
36, 54, 18, 27, 9, 18.5, 4.5
A. 4.5
B. 18.5
C. 54
D. 18
B. 18.5
73. A man buys a watch for Rs. 1950 in cash and sells it for Rs. 2200 at a credit of
1 year. If the rate of interest is 10% per annum, the man:
A. gains Rs. 55
B. gains Rs. 50
C. loses Rs. 30
D. gains Rs. 30
B. gains Rs. 50
75. A man walked diagonally across a square lot. Approximately, what was the
percent saved by not walking along the edges?
A. 20
B. 24
C. 30
D. 33
C. 30
76. A man took loan from a bank at the rate of 12% p.a. simple interest. After 3
years he had to pay Rs. 5400 interest only for the period. The principal amount
borrowed by him was:
A. Rs. 2000
B. Rs. 10,000
C. Rs. 15,000
D. Rs. 20,000
C. Rs. 15,000
77. One pipe can fill a tank three times as fast as another pipe. If together the two
pipes can fill the tank in 36 minutes, then the slower pipe alone will be able to fill
the tank in:
A. 81 min.
B. 108 min.
C. 144 min.
D. 192 min.
C. 144 min.
80. 3 pumps, working 8 hours a day, can empty a tank in 2 days. How many hours
a day must 4 pumps work to empty the tank in 1 day?
A. 9
B. 10
C. 11
D. 12
D. 12
82. The least perfect square, which is divisible by each of 21, 36 and 66 is:
A. 213444
B. 214344
C. 214434
D. 231444
A. 213444
83. .009:? = .01
A) .0009
B) .09
C) .9
D) 9
C) .9
85. Find the greatest number that will divide 43, 91 and 183 so as to leave the
same remainder in each case.
A. 4
B. 7
C. 9
D. 13
A. 4
86.There are 2 jars. One jar with the capacity of 5 ltrs and another with a capacity
of 3 ltrs. You should fill 4ltrs of water using both of these jars, there's no
measuring instrument available to measure. how will you fill 4 ltrs of water?
Solution
Pour the water from 5 ltr. jar to 3 ltr. jar, extra 2 ltr. water can be measured.
Repeat this process one more time, to get 2+2= 4 ltr. of water
87.The average speed of a man running a lap is 150 mph. He covers first two fifth
of the lap at a speed of 123 mph and the second two fifth distance by 164 mph, so
what is the time taken by him to cover the remaining one fifth distance?
Solution
(123+164+x)/3=150
287+x=450
x=163 mph
88.In an exam, there were 25 math qns and 75 nonmath qns. To answer a math
qn, a candidate was supposed to spend twice the time he spends to answer a
nonmath qn. If the entire exam duration was 2 hrs, find the time he spent on the
math qns.
Solution
Considering candidate uses full 2 hrs. or 120 min. of the exam for answering the
questions.
If candidate spent 'x' min. on non math question and '2x' min. on maths question,
then
(25*2x) +(75*x)=120, x=24/25
So time spent on math question=25*2*24/25=48 min.
89.In a jungle a man was at one end of the jungle. He has to give a 2 pieces of cake
to his friend who was at the other end of the jungle. There were 7 bridges on the
way with 7 gatekeepers. Each gatekeeper will take half of the cake he has and
will give one piece back to him. How many cakes should the man carry initially?
Solution
Answer is 2 cakes...
According to the condition, "Each gatekeeper will take half of the cake he has and
will give one piece back to him",
At the first gate, 2/2=1 cake is with the boy and the gatekeeper returns one cake.
So 1+1=2.
So, the boy again has 2 cakes.
Similar steps for all the gatekeepers.
Finally he will give 2 cakes to his friend.
90.There is a school with 100 students and correspondingly 100 lockers, all of
which start off closed. The first student opens every locker and the second
students closes every other locker starting with the second (2,4,6...etc..) . The 3rd
student changes the state of the lockers numbered (3,6,9.. etc.). The fourth
student changes the state of the lockers numbered (4,8,12.. etc..).. This continues
until all the 100 students passes along the lockers.. when all the 100 student is
done which locker is closed and which locker is in open condition?
when calculating for first 10 doors we come to know a pattern that the squared
numbered doors are open.Henceforth we come to a conclusion that squared
numbers from 1-100 i.e 1,4,9,16,25,36,49,64,81,100 will be open and the rest
doors will be closed.
so (1387*1)+(1387*9)= 1387+12483
here the unit digit is 7+3=10
hence the answer is 0
92.A 2 digit number is divided by the sum of digits then it gives square root of the
number. Find the 2 digit number.
Solution
Ans: 81
Let the the two digit number be xy
Given,
Xy / (x+y) =square root of xy
there are six ,2 digit whole square 16,25,36,49,64,81
So if we take 81
81/(8+1)=9
Square root of 81 is also 9
So the 2 digit number is 81
Model 5
ROW
1 1 1 1 1
ROW
2 2 4 8 16
ROW
3 3 9 27 81
ROW
4 4 16 64 256
a r e
l o a
f u r
Matrix 1
d e g
l q r
f r s
Matrix 2
w o i
e v u
t a r
Matrix 3
6.If the elements of matrix 2 are concatenated (appended at the end) with the
respective elements of matrix 3 and then the elements of resultant matrix are
concatenated with matrix 1 then what will be the last element in dictionary
among the 9 elements?
a) uar b) uet c) uux d) ufe
7.How many columns have at least one vowel?
a) 6 b) 7 c) 8 d) none of these
8.If the alphabets from all the matrices are taken, how many unique consonants
will we get?
a) 6 b) 8 c) 10 d) 12
Directions 9-12: In the matrix given below Row 1, Row 2 and Row 3 are families.
Answer the questions on basis of this information.
A D G
B E A
C G E
9.How many pairs of friends are there (assuming friend of friend is a friend)?
a) 3 b) 4 c) 5 d) 6
11.If E becomes enemy of B, how many pair of enemies are there (assuming
enemy of enemy is an enemy)?
a) 12 b) cannot be determined
c) a contradiction occurs d) none of these
12.Who can be removed from the matrix so that the number of pair of friends
remains still the same?
a) A b) c c) G d) none of these
91 -76 93 08
04 24 36 26
45 75 51 14
13.If all the numbers above 90 are added and then all the number below 10 are
multiplied. What will be the resultant of division of addition of numbers above 50
to the multiplied numbers below 10?
a) 1 b) 348 c) 225d) None of these
14.If row 1 is added with row 2, row 3 is added with row 4, how many prime
numbers will be there?
a) 0 b) 1 c) 2 d) none of these
15.If column 1 is interchanged with column 4 and row 1 is subtracted from row 4,
how many multiples of 5 will be there?
a) 2 b) 3 c) 4 d) 6
2. 3,4,12,5,6,……….
a) 30 b) 51 c) 60 d) 72
3. 1.9, 2.95,4,5.05,6.2, ……
a) 7.25 b) 735 c) 7.35 d) 4.8
4. 23,8,34,81,33,………
a) 44 b) 57 c) 27 d) 47
5. 8,64,216,………
a) 576b) 512 c) 144d) 1024
6. 2,3,5,7,11,……….
a) 13 b) 15 c) 19 d) 23
7.27,31,40,56,81,……..
a) 91 b) 100 c) 117d) 193
8.999,777,666,444,…………..
a) 222 b) 3333 c) 333 d) 111
9.1,1,2,3,5,8,13,……..,34,55
a) 99 b) 40 c) 21 d) 23
10. 0,1,32,243,…………
a) 1512 b) 1000 c) 1024 d) 1054
12.15,31,63,80,242,………….
a) 691b) 451 c) 600d) 728
13.4,36,144,400,……….
a) 500b) 676 c) 900d) 1024
14.14,26,38,49,50,………..
a) 61 b) 51 c) 50 d) 62
15 1,1/3,1/6,1/18,1/36,………….
a) 1/108 b) 1/72 c) 1/144 d) 1/48 16
17.24,39,416,525,……..
a) 687b) 688 c) 639d) 636
18.12,50,6,3,0.18,………
a) 0.0036 b) 0.0054 c) 0.0063 d) 0.0064
19.24,/,6,X,64,-, 252,……..,
a)+ b) = c) - d) ! 20 4,9,25,49,121,169,
20.4,9,25,49,121,169,
a) 225 b) 256 c) 289d) 324
1. In a class, 24 boys are there and one seventh of total are girls. How many
students
are there in total?
a) 28 b) 30 c) 32 d) none of these
2. A mixture has milk and water in the ratio 5:1. 20 liters of water is added and
the ratio now becomes 5:6. How much milk was present in original mixture?
a) 15 liters b) 25 liters c) 20 liters d) 30 liters
4.What is the ratio of areas of circum circle and in circle of an equilateral triangle?
a) 1:2 b) 2:1 c) 3:1 d) 4:1
5.Two doctors, three lawyers and one teacher went for a picnic? How many
persons would have went for picnic at minimum if a person cannot be both
teacher and lawyer?
a) 6 b) 5 c) 3 d) 4
6.“asd fgr ghy” stands for “let it be”. “uio fgr wet” stands for “let us go”. “wet mkl
asd” stands for “go with it”. What is the code for “be”?
a) asd b) ghyc) fgr d) none of these
7.The weight age given to various subjects while calculating total marks of a
student is inversely proportional to maximum marks of the subject. If math has
weight age 0.5 and maximum marks 100, and weight age for science is 0.875,
what are the maximum marks for science?
a) 36 b) 73 c) 57 d) 100
8.The population of mice in a market doubles every day. Every day 20 mice are
killed. How many mice are there if after every three days, the number of mice
becomes same again?
a) 36 b) 12 c) 60 d) 20
9.If printing a page requires 2mg of ink, how many rims of 500 pages can be
printed
with 1 kg of ink?
a) 200b) 500 c) 1000 d) 2000
10.Three numbers are in A.P., and the product of them is same as product of
smallest and largest. What is the middle number?
a) 1 b) -1 c) 2 d) -2
11.A can complete 10 rounds of park in the same time as B completes 6 rounds. If
circumference of track is 200 m, how much start A can give to B in a race of 1
round?
a) 60 meters b) 80 metersc) 100 meters d) none of these
Answer set
Section – 1: Matrix Test
1.b
2.a
3.d
4.a
5.c
6.a
7.b
8.c
9.a
10. b
11. c
12. d
13. d
14. a
15. b
1.c
2.a
3.c
4.c
5.b
6.a
7.c
8.c
9.c
10. c
11. b
12. d
13. c
14. d
15. a
16. b
17. d
18. b
Model 6
Predict the Output Questions
1. int main()
{
char *ptr = "geeksforgeeks";
printf("%c\n", *&*&*ptr);
getchar();
return 0;
}
Output: g
Explanation: The operator * is used for dereferencing and the operator & is used
to get the address. These operators cancel effect of each other when used one
after another. We can apply them alternatively any no. of times. For example *ptr
gives us g, &*ptr gives address of g, *&*ptr again g, &*&*ptr address of g, and
finally *&*&*ptr gives ‘g’
2.int main()
{
char *ptr = "geeksforgeeks";
printf("%s\n", *&*&ptr);
getchar();
return 0;
}
Output: geeksforgeeks
getchar();
return 0;
}
Output: 36
Explanation:
Preprocessor replaces square(6) by 6*6 and the expression becomes x = 36/6*6
and value of x is calculated as 36. If we want correct behavior from macro
square(x), we should declare it as
#define square(x) ((x)*(x)) /* Note that the expression
(x*x) will also fail for square(6-2) */
4. int main()
{
int x = 5;
int * const ptr = &x;
++(*ptr);
printf("%d", x);
getchar();
return 0;
}
Output: 6
Explananation:
int * const ptr —> ptr is constant pointer. You can change the value at the location
pointed by pointer p, but you can not change p to point to other location.
int const * ptr —> ptr is a pointer to a constant. You can change ptr to point other
variable. But you cannot change the value pointed by ptr.
Therefore above program works well because we have a constant pointer and we
are not changing ptr to point to any other location. We are only icrementing value
pointed by ptr.
5.int main()
{
int x = 5;
int const * ptr = &x;
++(*ptr);
printf("%d", x);
getchar();
return 0;
}
Output: Compile Time Error
6. #include<stdio.h>
int main()
{
int n;
for(n = 7; n!=0; n--)
printf("n = %d", n--);
getchar();
return 0;
}
Output:Above program goes in infinite loop because n is never zero when loop
condition (n != 0) is checked.
7.#include<stdio.h>
int main()
{
printf("%x", -1<<1);
getchar();
return 0;
}
Output is dependent on the compiler. For 32 bit compiler it would be fffffffe and
for 16 bit it would be fffe.
8. # include <stdio.h>
# define scanf "%s Geeks For Geeks "
main()
{
printf(scanf, scanf);
getchar();
return 0;
}
9.#include <stdlib.h>
#include <stdio.h>
enum {false, true};
int main()
{
int i = 1;
do
{
printf("%d\n", i);
i++;
if (i < 15)
continue;
} while (false);
getchar();
return 0;
}
Output: 1
Explanation: The do wile loop checks condition after each iteration. So after
continue statement, control transfers to the statement while(false). Since the
condition is false ‘i’ is printed only once.
10.char *getString()
{
char *str = "Nice test for strings";
return str;
}
int main()
{
printf("%s", getString());
getchar();
return 0;
}
11.char *getString()
{
char str[] = "Will I be printed?";
return str;
}
int main()
{
printf("%s", getString());
getchar();
}
12.int main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
Output: 0 0 0 0
Explanation: Since i is a static variable and is stored in Data Section, all calls to
main share same i.
13.int main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
Output: 5 4 3 2 1
Explanation: Same as previous question. The only difference here is, sequence of
calling main and printf is changed, therefore different output.
14.int main()
{
int x;
printf("%d",scanf("%d",&x));
/* Suppose that input value given
for above scanf is 20 */
return 1;
}
Output: 1
scanf returns the no. of inputs it has successfully read.
getchar();
return 0;
}
Output: 16 21
Explanation:
Initially i = 0. Since case 0 is true i becomes 5, and since there is no break
statement till last statement of switch block, i becomes 16. Now in next iteration
no case is true, so execution goes to default and i becomes 21.
16.#include <stdio.h>
int main()
{
printf("%d", main);
getchar();
return 0;
}
Output: Address of function main.
Explanation: Name of the function is actually a pointer variable to the function
and prints the address of the function.
17.#include <stdio.h>
int main()
{
printf("\new_c_question\by");
printf("\rgeeksforgeeks");
getchar();
return 0;
}
Output: geeksforgeeksl
Explanation: First printf prints “ew_c_questioy”. Second printf has \r in it so it
goes back to start of the line and starts printing characters.
18.#include <stdio.h>
int main()
{
int i;
i = 1, 2, 3;
printf("i = %d\n", i);
getchar();
return 0;
}
Output: 1
19.#include <stdio.h>
int main()
{
int i;
i = (1, 2, 3);
printf("i = %d\n", i);
getchar();
return 0;
}
Output: 3
20.#include <stdio.h>
int main()
{
int first = 50, second = 60, third;
third = first /* Will this comment work? */ + second;
printf("%d /* And this? */ \n", third);
getchar();
return 0;
}
21.#include‹stdio.h›
int main()
{
struct site
{
char name[] = "GeeksforGeeks";
int no_of_pages = 200;
};
struct site *ptr;
printf("%d",ptr->no_of_pages);
printf("%s",ptr->name);
getchar();
return 0;
}
Output:
Compiler error
Explanation:
Note the difference between structure/union declaration and variable
declaration. When you declare a structure, you actually declare a new data type
suitable for your purpose. So you cannot initialize values as it is not a variable
declaration but a data type declaration.
22.int main()
{
char a[2][3][3] = {'g','e','e','k','s','f','o',
'r','g','e','e','k','s'};
printf("%s ", **a);
getchar();
return 0;
}
Output:
geeksforgeeks
Explanation:
We have created a 3D array that should have 2*3*3 (= 18) elements, but we are
initializing only 13 of them. In C when we initialize less no of elements in an array
all uninitialized elements become ‘\0’ in case of char and 0 in case of integers.
23.int main()
{
char str[]= "geeks\nforgeeks";
char *ptr1, *ptr2;
ptr1 = &str[3];
ptr2 = str + 5;
printf("%c", ++*str - --*ptr1 + *ptr2 + 2);
printf("%s", str);
getchar();
return 0;
}
Output:
heejs
forgeeks
Explanation:
Initially ptr1 points to ‘k’ and ptr2 points to ‘\n’ in “geeks\nforgeeks”. In print
statement value at str is incremented by 1 and value at ptr1 is decremented by 1.
So string becomes “heejs\nforgeeks” .
First print statement becomes
printf(“%c”, ‘h’ – ‘j’ + ‘n’ + 2)
‘h’ – ‘j’ + ‘\n’ + 2 = -2 + ‘\n’ + 2 = ‘\n’
First print statements newline character. and next print statement prints
“heejs\nforgeeks”.
24.#include <stdio.h>
int fun(int n)
{
int i, j, sum = 0;
for(i = 1;i<=n;i++)
for(j=i;j<=i;j++)
sum=sum+j;
return(sum);
}
int main()
{
printf("%d", fun(15));
getchar();
return 0;
}
Output: 120
Explanation: fun(n) calculates sum of first n integers or we can say it returns
n(n+1)/2.
25.#include <stdio.h>
int main()
{
int c = 5, no = 1000;
do {
no /= c;
} while(c--);
26.int main()
{
while(1){
if(printf("%d",printf("%d")))
break;
else
continue;
}
return 0;
}
Output:
Can’t be predicted
Explanation:
The condition in while loop is 1 so at first shot it looks infinite loop. Then there
are break and continue in the body of the while loop, so it may not be infinite
loop. The break statement will be executed if the condition under if is met,
otherwise continue will be executed. Since there’s no other statements after
continue in the while loop, continue doesn’t serve any purpose. In fact it is
extraneous. So let us see the if condition. If we look carefully, we will notice that
the condition of the if will be met always, so break will be executed at the first
iteration itself and we will come out of while loop. The reason why the condition
of if will be met is printf function. Function printf always returns the no. of bytes
it has output. For example, the return value of printf(“geeks”) will be 5 because
printf will output 5 characters here. In our case, the inner printf will be executed
first but this printf doesn’t have argument for format specifier i.e. %d. It means
this printf will print any arbitrary value. But notice that even for any arbirary
value, the no. of bytes output by inner printf would be non-zero. And those no. of
bytes will work as argument to outer printf. The outer printf will print that many
no. of bytes and return non-zero value always. So the condition for if is also true
always. Therefore, the while loop be executed only once. As a side note, even
without outer printf also, the condition for if is always true.
27.int main()
{
unsigned int i=10;
while(i-- >= 0)
printf("%u ",i);
return 0;
}
Output:
9 8 7 6 5 4 3 2 1 0 4294967295 4294967294 …… (on a machine where int is 4
bytes long)
9 8 7 6 5 4 3 2 1 0 65535 65534 …. (on a machine where int is 2 bytes long)
Explanation:
Let us examine the condition of while loop. It is obvious that as far as the
condition of while loop is met, printf will be executed. There are two operators in
the condition of while loop: post-decrement operator and comparison operator.
From operator precedence, we know that unary operator post-decrement has
higher priority than comparison operator. But due to post-decrement property,
the value of i will be decremented only after it had been used for comparison. So
at the first iteration, the condition is true because 10>=0 and then i is
decremented. Therefore 9 will be printed. Similarly the loop continues and the
value of i keeps on decrementing. Let us see what what happen when condition of
while loop becomes 0 >= 0. At this time, condition is met and i is decremented.
Since i is unsigned integer, the roll-over happens and i takes the value of the
highest +ve value an unsigned int can take. So i is never negative. Therefore, it
becomes infinite while loop.
As a side note, if i was signed int, the while loop would have been terminated
after printing the highest negative value.
28.int main()
{
int x,y=2,z,a;
if ( x = y%2)
z =2;
a=2;
printf("%d %d ",z,x);
return 0;
}
Output:
< some garbage value of z > 0
Explanation:
This question has some stuff for operator precedence. If the condition of if is met,
then z will be initialized to 2 otherwise z will contain garbage value. But the
condition of if has two operators: assignment operator and modulus operator.
The precedence of modulus is higher than assignment. So y%2 is zero and it’ll be
assigned to x. So the value of x becomes zero which is also the effective condition
for if. And therefore, condition of if is false.
29.int main()
{
int a[10];
printf("%d",*a+1-*a+3);
return 0;
}
Output: 4
Explanation:
From operator precedence, de-reference operator has higher priority than
addition/subtraction operator. So de-reference will be applied first. Here, a is an
array which is not initialized. If we use a, then it will point to the first element of
the array. Therefore *a will be the first element of the array. Suppose first element
of array is x, then the argument inside printf becomes as follows. It’s effective
value is 4.
x+1–x+3=4
Output:
10
Explanation:
This program deals with macros, their side effects and operator precedence. Here
prod is a macro which multiplies its two arguments a and b. Let us take a closer
look.
prod(a, b) = a*b
prod(x+2, y-1) = x+2*y-1 = 3+2*4-1 = 3+8-1=10
If the programmer really wanted to multiply x+2 and y-1, he should have put
parenthesis around a and b as follows.
prod(a,b) = (a)*(b)
This type of mistake in macro definition is called – macro side-effects.
31.int main()
{
unsigned int i=65000;
while ( i++ != 0 );
printf("%d",i);
return 0;
}
Output:
1
Explanation:
It should be noticed that there’s a semi-colon in the body of while loop. So even
though, nothing is done as part of while body, the control will come out of while
only if while condition isn’t met. In other words, as soon as i inside the condition
becomes 0, the condition will become false and while loop would be over. But also
notice the post-increment operator in the condition of while. So first i will be
compared with 0 and i will be incremented no matter whether condition is met
or not. Since i is initialized to 65000, it will keep on incrementing till it reaches
highest positive value. After that roll over happens, and the value of i becomes
zero. The condition is not met, but i would be incremented i.e. to 1. Then printf
will print 1.
32.int main()
{
int i=0;
while ( +(+i--) != 0)
i-=i++;
printf("%d",i);
return 0;
}
Output:
-1
Explanation:
Let us first take the condition of while loop. There are several operator there.
Unary + operator doesn’t do anything. So the simplified condition becomes (i–) !=
0. So i will be compared with 0 and then decremented no matter whether
condition is true or false. Since i is initialized to 0, the condition of while will be
false at the first iteration itself but i will be decremented to -1. The body of while
loop will not be executed. And printf will print -1.
33.int main()
{
float f=5,g=10;
enum{i=10,j=20,k=50};
printf("%d\n",++k);
printf("%f\n",f<<2);
printf("%lf\n",f%g);
printf("%lf\n",fmod(f,g));
return 0;
}
Output:
Program will not compile and give 3 errors
Explanation:
Here, i, j and k are inside the enum and therefore, they are like constants. In other
words, if want to use 10 anywhere in the program , we can use i instead. In the
first printf, the value of i is being modified which is not allowed because it’s enum
constant. In the second printf, left-shift operator is being applied on a float which
is also not allowed. Similarly, in the third printf, modulus operator is being
applied on float f and g which is also not allowed.
34.int main()
{
int i=10;
void pascal f(int,int,int);
f(i++, i++, i++);
printf(" %d",i);
return 0;
}
void pascal f(integer :i,integer:j,integer :k)
{
write(i,j,k);
}
Output:
Program will give compile-time error
Explanation:
Compiler specific question. Not all compilers support this.
Otherwise, pascal enforces left to right processing of arguments. So even though,
the argument processing order can be changed by the use of pascal, we can’t use
Pascal language routines such as write inside C program.
main()
{
int i=10;
f(i++,i++,i++);
printf(" %d\n",i);
i=10;
f(i++,i++,i++);
printf(" %d",i);
}
Output:
Compiler specific question. Not all the compilers allow this.
Explanation:
This question deals with the argument passing mechanism. If we call a function,
the order in which the arguments of the function are processed is not governed
by C Standard. So one compiler can process the arguments from left to right while
the other compiler can process them right to left. Usually, the programs are not
affected with this because the arguments of the programs are different. For
example if we call funtion fun as fun(i,j), then no matter in which order the
arguments are processed, the value of i and j will be consistent.
But in this case, we are passing the arguments to function f using the same
variable. So the order in which arguments are processed by the function will
determine the value of those arguments. cdecl enforces right to left processing of
arguments while pascal enforces left to right processing of arguments.
So the value of i, j and k inside the first function f will be 10, 11 and 12
respectively while the value of i, j and k inside the second function f will be 12, 11
and 10 respectively.
36.int main()
{
int i = 0;
while (i <= 4)
{
printf("%d", i);
if (i > 3)
goto inside_foo;
i++;
}
getchar();
return 0;
}
void foo()
{
inside_foo:
printf("PP");
}
Output: Compiler error: Label “inside_foo” used but not defined.
Explanation: Scope of a label is within a function. We cannot goto a label from
other function.
37.#define a 10
int main()
{
#define a 50
printf("%d",a);
getchar();
return 0;
}
Output: 50
Preprocessor doesn’t give any error if we redefine a preprocessor directive. It
may give warning though. Preprocessor takes the most recent value before use of
and put it in place of a.
38.int main()
{
char str[] = "geeksforgeeks";
char *s1 = str, *s2 = str;
int i;
getchar();
return 0;
}
Output
ggggggggeeksf
Explanation
Both s1 and s2 are initialized to str. In first loop str is being printed and s1 is
being incremented, so first loop will print only g. In second loop s2 is
incremented and s2 is printed so second loop will print “g e e k s f ”
39.int main()
{
char str[] = "geeksforgeeks";
int i;
for(i=0; str[i]; i++)
printf("\n%c%c%c%c", str[i], *(str+i), *(i+str), i[str]);
getchar();
return 0;
}
Output:
gggg
eeee
eeee
kkkk
ssss
ffff
oooo
rrrr
gggg
eeee
eeee
kkkk
ssss
Explanaition:
Following are different ways of indexing both array and string.
arr[i]
*(arr + i)
*(i + arr)
i[arr]
So all of them print same character.
40.int main()
{
char *p;
printf("%d %d ", sizeof(*p), sizeof(p));
getchar();
return 0;
}
41.#include<stdio.h>
int main()
{
int x = 5, p = 10;
printf("%*d", x, p);
getchar();
return 0;
}
Output:
10
Explanation:
Please see standard printf function definition
int printf ( const char * format, ... );
format: String that contains the text to be written to stdout. It can optionally
contain embedded format tags that are substituted by the values specified in
subsequent argument(s) and formatted as requested. The number of arguments
following the format parameters should at least be as much as the number of
format tags. The format tags follow this prototype:
%[flags][width][.precision][length]specifier
The main thing to note is below the line about precision
* (star): The precision is not specified in the format string, but as an additional
integer value argument preceding the argument that has to be formatted.
So, in the above example 5 is precision and 10 is the actual value to be printed.
42.int main()
{
char arr[] = "geeksforgeeks";
char *ptr = arr;
while(*ptr != '\0')
++*ptr++;
printf("%s %s", arr, ptr);
getchar();
return 0;
}
Output: hffltgpshfflt
Explanation:
The crust of this question lies in expression ++*ptr++.
If one knows the precedence and associativity of the operators then there is
nothing much left. Below is the precedence of operators.
Postfixx ++ left-to-right
Prefix ++ right-to-left
Dereference * right-to-left
43.int main()
{
signed char i=0;
for(; i >= 0; i++);
printf("%d\n", i);
getchar();
return 0;
}
Output: -128
Explanation:
Here, the first thing to be noticed is the semi-colon in the end of for loop. So
basically, there’s no body for the for loop. And printf will print the value of i when
control comes out of the for loop. Also, notice that the first statement i.e.
initializer in the for loop is not present. But i has been initialized at the
declaration time. Since i is a signed character, it can take value from -128 to 127.
So in the for loop, i will keep incrementing and the condition is met till roll over
happens. At the roll over, i will become -128 after 127, in that case condition is
not met and control comes out of the for loop.
44.#include <stdio.h>
void fun(const char **p) { }
int main(int argc, char **argv)
{
fun(argv);
getchar();
return 0;
}
45.int main()
{
int c=5;
printf("%d\n%d\n%d", c, c <<= 2, c >>= 2);
getchar();
}
46.int main()
{
char arr[] = {1, 2, 3};
char *p = arr;
if(&p == &arr)
printf("Same");
else
printf("Not same");
getchar();
}
Output: Not Same
&arr is an alias for &arr[0] and returns the address of the first element in array,
but &p returns the address of pointer p.
47.int main()
{
char arr[] = {1, 2, 3};
char *p = arr;
printf(" %d ", sizeof(p));
printf(" %d ", sizeof(arr));
getchar();
}
Output 4 3
sizeof(arr) returns the amount of memory used by all elements in array
and sizeof(p) returns the amount of memory used by the pointer variable itself.
48.int x = 0;
int f()
{
return x;
}
int g()
{
int x = 1;
return f();
}
int main()
{
printf("%d", g());
printf("\n");
getchar();
}
Output: 0
In C, variables are always statically (or lexically) scoped. Binding of x inside f() to
global variable x is defined at compile time and not dependent on who is calling
it. Hence, output for the above program will be 0.
49.#include<stdio.h>
int main()
{
typedef int i;
i a = 0;
printf("%d", a);
getchar();
return 0;
}
Output: 0
There is no problem with the program. It simply creates a user defined type i and
creates a variable aof type i.
50.#include<stdio.h>
int main()
{
typedef int *i;
int j = 10;
i *a = &j;
printf("%d", **a);
getchar();
return 0;
}
51.#include<stdio.h>
int main()
{
typedef static int *i;
int j;
i a = &j;
printf("%d", *a);
getchar();
return 0;
}
52.#include<stdio.h>
int fun(int n, int *fg)
{
int t, f;
if(n <= 1)
{
*fg = 1;
return 1;
}
t = fun(n-1, fg);
f = t + *fg;
*fg = t;
return f;
}
int main( )
{
int x = 15;
printf ( "%d\n", fun (5, &x));
getchar();
return 0;
}
Output:8
int main()
{
char *str = "geeksforgeeks";
printf("%d", fun(str));
getchar();
return 0;
}
Output: 13
Inside fun(), pointer str2 is initialized as str1 and str1 is moved till ‘\0’ is reached
(note ; after while loop). So str1 will be incremented by 13 (assuming that char
takes 1 byte).
Output: 20
Inside fun(), q is a copy of the pointer p. So if we change q to point something else
then p remains unaffected.
int main()
{
int r = 20;
int *p = &r;
fun(&p);
printf("%d", *p);
getchar();
return 0;
}
Output 10
Note that we are passing address of p to fun(). p in fun() is actually a pointer to p
in main() and we are changing value at p in fun(). So p of main is changed to point
q of fun().
56.int main()
{
char arr[] = "geeksforgeeks";
printf("%d", sizeof(arr));
getchar();
return 0;
}
Output: 14
The string “geeksforgeeks” has 13 characters, but the size is 14 because compiler
includes a single ‘\0’ (string terminator) when char array size is not explicitly
mentioned.
57.In below program, what would you put in place of “?” to print “geeks”.
Obviously, something other than “geeks”.
int main()
{
char arr[] = "geeksforgeeks";
printf("%s", ?);
getchar();
return 0;
}
Output: (arr+8)
The printf statement prints everything starting from arr+8 until it finds ‘\0’
58.int main()
{
int x, y = 5, z = 5;
x = y==z;
printf("%d", x);
getchar();
return 0;
}
The crux of the question lies in the statement x = y==z. The operator == is
executed before = because precedence of comparison operators (<=, >= and ==) is
higher than assignment operator =.
The result of a comparison operator is either 0 or 1 based on the comparison
result. Since y is equal to z, value of the expression y == z becomes 1 and the
value is assigned to x via the assignment operator.
59.int main()
{
printf(" \"GEEKS %% FOR %% GEEKS\"");
getchar();
return 0;
}
60.#include<stdio.h>
int main()
{
int a;
char *x;
x = (char *) &a;
a = 512;
x[0] = 1;
x[1] = 2;
printf("%d\n",a);
getchar();
return 0;
}
61.int main()
{
int f = 0, g = 1;
int i;
for(i = 0; i < 15; i++)
{
printf("%d \n", f);
f = f + g;
g = f - g;
}
getchar();
return 0;
}
int func(int i)
{
if(i%2) return (i++);
else return func(func(i-1));
}
Output: If n is odd then returns n, else returns (n-1). So if n is 12 then we get and
if n is 11 then we get 11.
63.#include<stdio.h>
int main(void)
{
int a = 1;
int b = 0;
b = ++a + ++a;
printf("%d %d",a,b);
getchar();
return 0;
}
Output: 3 6
64.#include<stdio.h>
int main()
{
int a[] = {1, 2, 3, 4, 5, 6};
int *ptr = (int*)(&a+1);
printf("%d ", *(ptr-1) );
getchar();
return 0;
}
Output: 6
&a is address of the whole array a[]. If we add 1 to &a, we get “base address of a[]
+ sizeof(a)”. And this value is typecasted to int *. So ptr – 1 points to last element
of a[]
65.#include <stdio.h>
char* fun()
{
return "awake";
}
int main()
{
printf("%s",fun()+ printf("I see you"));
getchar();
return 0;
}
66.#include <stdio.h>
int main()
{
unsigned i ;
for( i = 0 ; i < 4 ; ++i )
{
fprintf( stdout , "i = %d\n" , ("11213141") ) ;
}
getchar();
return 0 ;
}
Output: Prints different output on different machines.
Explanation:The format specifier is %d, converts the base address of string
“11213141” as an integer. The base address of string depends on memory
allocation by the compiler. The for loop prints same address four times. Try to use
C++ streams, you will see power of type system.
67.#include<stdio.h>
#define R 10
#define C 20
int main()
{
int (*p)[R][C];
printf("%d", sizeof(*p));
getchar();
return 0;
}
68.#include<stdio.h>
#define f(g,g2) g##g2
int main()
{
int var12 = 100;
printf("%d", f(var,12));
getchar();
return 0;
}
Output: 100
The operator ## is called “Token-Pasting” or “Merge” Operator. It merges two
tokens into one token. So, after preprocessing, the main function becomes as
follows, and prints 100.
69.#include<stdio.h>
int main()
{
unsigned int x = -1;
int y = ~0;
if(x == y)
printf("same");
else
printf("not same");
printf("\n x is %u, y is %u", x, y);
getchar();
return 0;
}
70.#include<stdio.h>
int fun()
{
static int num = 40;
return num--;
}
int main()
{
for(fun(); fun(); fun())
{
printf("%d ", fun());
}
getchar();
return 0;
}
Output: 38 35 32 29 26 23 20 17 14 11 8 5 2
Since num is static in fun(), the old value of num is preserved for subsequent
functions calls. Also, since the statement return num– is postfix, it returns the old
value of num, and updates the value for next function call.
71.#include<stdio.h>
int main()
{
char *s[] = { "knowledge","is","power"};
char **p;
p = s;
printf("%s ", ++*p);
printf("%s ", *p++);
printf("%s ", ++*p);
getchar();
return 0;
}
72.#include <stdio.h>
int main()
{
int a = 10, b = 20, c = 30;
if (c > b > a)
{
printf("TRUE");
}
else
{
printf("FALSE");
}
getchar();
return 0;
}
Output: FALSE
Let us consider the condition inside the if statement. Since there are two greater
than (>) operators in expression “c > b > a”, associativity of > is considered.
Associativity of > is left to right. So, expression c > b > a is evaluated as ( (c > b) >
a ) which is false.
73.int main()
{
int x = 10;
static int y = x;
if(x == y)
printf("Equal");
else if(x > y)
printf("Greater");
else
printf("Less");
getchar();
return 0;
}
int main()
{
int i;
for (i = 1; i != 10; i += 2)
{
printf(" GeeksforGeeks ");
}
getchar();
return 0;
}
The loop termination condition never becomes true and the loop prints
GeeksforGeeks infinite times. In general, if a for or while statement uses a loop
counter, then it is safer to use a relational operator (such as <) to terminate the
loop than using an inequality operator (operator !=).
75.#include<stdio.h>
struct st
{
int x;
struct st next;
};
int main()
{
struct st temp;
temp.x = 10;
temp.next = temp;
printf("%d", temp.next.x);
getchar();
return 0;
}
76.#include<stdio.h>
#define fun (x) (x)*10
int main()
{
int t = fun(5);
int i;
for(i = 0; i < t; i++)
printf("GeesforGeeks\n");
return 0;
}
77.#include<stdio.h>
#define fun(x) (x)*10
int main()
{
int t = fun(5);
int i;
for(i = 0; i < t; i++)
printf("GeesforGeeks\n");
return 0;
}
Output: prints “GeeksforGeeks” 50 times.
78.#include<stdio.h>
int main()
{
int i = 20,j;
i = (printf("Hello"), printf(" All Geeks "));
printf("%d", i);
return 0;
}
79.#include<stdio.h>
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for(i = star; i <= zee; i++)
{
printf("%d ", i);
}
return 0;
}
Output:
compiler error: redeclaration of enumerator 'star'
In the above program, enumartion constant ‘star’ appears two times in main()
which causes the error. An enumaration constant must be unique within the
scope in which it is defined. The following program works fine and prints 0 1 2 as
the enumaration constants automatically get the values starting from 0.
80.#include<stdio.h>
int main()
{
enum channel {star, sony, zee};
int i = 0;
for(i = star; i <= zee; i++)
{
printf("%d ", i);
}
return 0;
}
Output:
012
81.#include<stdio.h>
int main()
{
int i, j;
int p = 0, q = 2;
return 0;
}
Output:
GeeksforGeeks
GeeksforGeeks
i < p, j < q
When two expressions are separated by comma operator, the first expression (i <
p) is executed first. Result of the first expression is ignored. Then the second
expression (j < q) is executed and the result of this second expression is the final
result of the complete expression (i < p, j < q). The value of expression 'j < q' is
true for two iterations, so we get "GeeksforGeeks" two times on the screen.
82.#include <stdio.h>
#define R 4
#define C 4
int main()
{
int mat[R][C] = { {1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}
};
printf("Original Matrix \n");
printMatrix(mat);
modifyMatrix(mat);
return 0;
}
Output:
Original Matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Matrix after modification
1 2 3 4
5 6 7 8
9 100 11 12
13 200 15 16
83.#include<stdio.h>
int main()
{
int arr[] = {10, 20, 30, 40, 50, 60};
int *ptr1 = arr;
int *ptr2 = arr + 5;
printf ("ptr2 - ptr1 = %d\n", ptr2 - ptr1);
printf ("(char*)ptr2 - (char*) ptr1 = %d", (char*)ptr2 - (char*)ptr1);
getchar();
return 0;
}
Output:
ptr2 - ptr1 = 5
(char*)ptr2 - (char*) ptr1 = 20
In C, array name gives address of the first element in the array. So when we do
ptr1 = arr, ptr1 starts pointing to address of first element of arr. Since array
elements are accessed using pointer arithmetic, arr + 5 is a valid expression and
gives the address of 6th element. Predicting value ptr2 – ptr1 is easy, it gives 5 as
there are 5 inetegers between these two addresses. When we do (char *)ptr2,
ptr2 is typecasted to char pointer. In expression “(int*)ptr2 – (int*)ptr1”, pointer
arithmetic happens considering character poitners. Since size of a character is
one byte, we get 5*sizeof(int) (which is 20) as difference of two pointers.
84.#include<stdio.h>
int main()
{
char arr[] = "geeksforgeeks";
char *ptr1 = arr;
char *ptr2 = ptr1 + 3;
printf ("ptr2 - ptr1 = %d\n", ptr2 - ptr1);
printf ("(int*)ptr2 - (int*) ptr1 = %d", (int*)ptr2 - (int*)ptr1);
getchar();
return 0;
}
Output:
ptr2 - ptr1 = 3
(int*)ptr2 - (int*) ptr1 = 0
85.#include<stdio.h>
int main()
{
char arr[] = "geeks\0 for geeks";
char *str = "geeks\0 for geeks";
printf ("arr = %s, sizeof(arr) = %d \n", arr, sizeof(arr));
printf ("str = %s, sizeof(str) = %d", str, sizeof(str));
getchar();
return 0;
}
Output:
arr = geeks, sizeof(arr) = 17
str = geeks, sizeof(str) = 4
Let us first talk about first output “arr = geeks”. When %s is used to print a string,
printf starts from the first character at given address and keeps printing
characters until it sees a string termination character, so we get “arr = geeks” as
there is a \0 after geeks in arr[].
Now let us talk about output “sizeof(arr) = 17”. When a character array is
initialized with a double quoted string and array size is not specified, compiler
automatically allocates one extra space for string terminator ‘\0′ , that is why size
of arr is 17.
Explanation for printing “str = geeks” is same as printing “arr = geeks”. Talking
about value of sizeof(str), str is just a pointer (not array), so we get size of a
pointer as output.
86.int main(void)
{
struct str
{
int i: 1;
int j: 2;
int k: 3;
int l: 4;
};
struct str s;
s.i = 1;
s.j = 2;
s.k = 5;
s.l = 10;
In the structure declaration, for structure member ‘i’, we used width of bit field as
1, width of ‘j’ as 2, and so on. At first, it looks we can store values in range [0-1]
for ‘i’, range [0-3] for ‘j’, and so on. But in the above declaration, type of bit fields is
integer (signed). That’s why out of available bits, 1 bit is used to store sign
information. So for ‘i’, the values we can store are 0 or -1 (for a machine that uses
two’s complement to store signed integers). For variable ‘k’, number of bits is 3.
Out of these 3 bits, 2 bits are used to store data and 1 bit is used to store sign.
87.int main(void)
{
struct str
{
unsigned int i: 1;
unsigned int j: 2;
unsigned int k: 3;
unsigned int l: 4;
};
struct str s;
s.i = 1;
s.j = 2;
s.k = 5;
s.l = 10;
getchar();
return 0;
}
output:
i: 1
j: 2
k: 5
l: 10
88.#include <stdio.h>
int main()
{
int arr[] = {};
printf("%d", sizeof(arr));
return 0;
}
Output: 0
C (or C++) allows arrays of size 0. When an array is declared with empty
initialization list, size of the array becomes 0.
89.#include<stdio.h>
int main()
{
int i, j;
int arr[4][4] = { {1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16} };
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
printf("%d ", j[i[arr]] );
printf("\n");
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16
Array elements are accessed using pointer arithmetic. So the meaning of arr[i][j]
and j[i[arr]] is same. They both mean (arr + 4*i + j). Similarly, the meaning of
arr[j][i] and i[j[arr]] is same.
90.#include<stdio.h>
int main()
{
int a[2][3] = {2,1,3,2,3,4};
printf("Using pointer notations:\n");
printf("%d %d %d\n", *(*(a+0)+0), *(*(a+0)+1), *(*(a+0)+2));
printf("Using mixed notations:\n");
printf("%d %d %d\n", *(a[1]+0), *(a[1]+1), *(a[1]+2));
return 0;
}
Output:
Using pointer notations:
213
Using mixed notations:
234
91.#include <stdio.h>
int main(void)
{
int i;
int power_of_ten[5] = {
00001,
00010,
00100,
01000,
10000,
};
return 0;
}
92.#include <stdio.h>
int main(void)
{
https://www.geeksforgeeks.org
return 0;
}
93.#include <stdio.h>
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
int main(void)
{
int i;
int arr[] = {1, 2, 3, 4, 5};
printf("\n");
return 0;
}
In above program, “ARRAY_SIZE” macro substitutes the expression to get the total
number of elements present in array, and we are printing these element by using
a for loop. But program doesn’t print anything. Let us see what is wrong with
code.
Value returned by the substituted expression is in “unsigned int” format, and
inside for loop we are comparing unsigned 5 with signed -1. In this comparison
-1 is promoted to unsigned integer. -1 in unsigned format is represented as all it’s
bit are set to 1 (i.e. 0xffffffff), which is too big number
After substituting value of macro, for loop look like this.
for (i = -1; 0xffffffff < 5; ++i)
In above loop indeed 0xffffffff is not less than 5, that's why for loop condition
fails, and program exits from loop without printing anything.
94.#include <stdio.h>
int main()
{
char a = 30;
char b = 40;
char c = 10;
char d = (a * b) / c;
printf ("%d ", d);
return 0;
}
At first look, the expression (a*b)/c seems to cause arithmetic overflow because
signed characters can have values only from -128 to 127 (in most of the C
compilers), and the value of subexpression ‘(a*b)’ is 1200. For example, the
following code snippet prints -80 on a 32 bit little endian machine.
char d = 1200;
printf ("%d ", d);
Arithmetic overflow doesn’t happen in the original program and the output of the
program is 120. In C, char and short are converted to int for arithmetic
calculations. So in the expression ‘(a*b)/c’, a, b and c are promoted to int and no
overflow happens.
95.#include<stdio.h>
int main()
{
int a, b = 10;
a = -b--;
printf("a = %d, b = %d", a, b);
return 0;
}
Output:
a = -10, b = 9
The statement ‘a = -b–;’ compiles fine. Unary minus and unary decrement have
save precedence and right to left associativity. Therefore ‘-b–‘ is treated as -(b–)
which is valid. So -10 will be assigned to ‘a’, and ‘b’ will become 9.
96.#include<stdio.h>
int main()
{
int i;
for (i = 0; i<5; i++)
{
int i;
i = 10;
printf("%d ", i) ;
}
return 0;
}
Here, it would seem that, as ‘i’ got assigned a value 10, so the loop will run only
one time because the loop condition will fail as ‘i’ becomes 11 the next time it
enters the loop. But the output is quite different than what we expected. The
reason behind this is the scope of variable is within the method. As soon as the
loop exits , i is counted according to i of for loop which makes the condition true
upto 5 times (0-4). See scope rules for more details.
Here, the loop runs according to the ‘i’ declared outside the loop, and hence it will
run five times and the ‘i’ inside the loop will be printed five times.
Output:
10 10 10 10 10
97.#include<stdio.h>
int main()
{
int i = 10;
static int x = i;
if (x==i)
printf("x and i are Equal\n");
return 0;
}
Here, it would seem that, as ‘x’ and ‘i’ are equal, so the output will be “x and i are
Equal”. But the output is quite unexpected.
As, static variables are load time entity while auto variables are run time entity
an We can not initialize any load time variable by the run time variable. So,the
output the c code above will show “Compile error”.
Output:
Compile error
98.#include <stdio.h>
#include <string.h>
int main()
{
printf("GEEKS size = %d \n\n", sizeof("GEEKS"));
printf("GEEKS length = %d \n", strlen("GEEKS"));
return 0;
}
sizeof() function returns the size of the string including null character while
strlen() function returns length of the string excluding null character.
So, the output will be as shown below :
Output:
GEEKS size = 6
GEEKS length = 5
99.#include <stdio.h>
int extern i;
int main()
{
printf("%d", i);
}
int i = 10;
With the help of extern keyword, the declaration of variable can be done any
where in the program. Here, i is a variable which is being declared after the printf
statement outside the main. Still, it can be accessed by the printf statement as it is
an extern variable.
Output:
10
100.#include<stdio.h>
int main()
{
int a = 10;
printf("%o %x", a, a);
return 0;
}
As, %o is used to print the number in octal number format and %x is used to
print the number in hexadecimal number format. And if we convert decimal 10 to
octal , we get 12 and in hexadecimal it will give a
Output:
12 a
101.#include<stdio.h>
int main()
{
printf("%s", "Geeks\nFor\nGeeks\nis\nthe\nbest");
}
102.#include <stdio.h>
int main()
{
int num = 2;
switch (num + 2)
{
case 1:
printf("Case 1: ");
case 2:
printf("Case 2: ");
case 3:
printf("Case 3: ");
default:
printf("Default: ");
}
return 0;
}
Output:
Default:
Explanation: In switch, an expression “num+2” where num value is 2 and after
addition the expression result is 4. Since there is no case defined with value 4 the
default case got executed.
103.#include<stdio.h>
void main()
{
int movie = 1;
switch (movie << (2 + movie))
{
default:
printf(" Traffic");
case 4:
printf(" Sultan");
case 5:
printf(" Dangal");
case 8:
printf(" Bahubali");
}
}
Output:
Bahubali
Explanation: We can write case statement in any order including the default case.
That default case may be first case, last case or in between the any case in the
switch case statement. The value of expression “movie << (2 + movie)" is 8.
104.#include<stdio.h>
#define L 10
void main()
{
auto a = 10;
switch (a, a*2)
{
case L:
printf("ABC");
break;
case L*2:
printf("XYZ");
break;
case L*3:
printf("PQR");
break;
default:
printf("MNO");
case L*4:
printf("www");
break;
}
}
Output:
XYZ
Explanation: In C, comma is also operator with least precedence. So if
x = (a, b);
Then x = b
Note: Case expression can be macro constant.
105.#include<stdio.h>
void main()
{
switch(2)
{
case 1L:
printf("No");
case 2L:
printf("%s","GEEKS");
goto Love;
case 3L:
printf("Please");
case 4L:Love:
printf("FOR");
}
}
Output:
GEEKSFOR
Explanation: It is possible to write label of goto statement in the case of switch
case statement.