C Interview Question-Part 2

Posted on:
tags: , , , , ,
 C Interview Question-Part1

1) What are Macros?
    Macros are preprocessor, it’s unique feature of C language. Preprocessor improves the readability of the program and hence the developed code is more efficient.
Preprocessor directives consist of three sub categories
•Macro substitution division
•Complier control division
•File inclusion division

2) What is the difference between char *a and char a[]?
    Char a[] = “Name”
    The above statement allocates 5 memory location, for the above declared statement.
    Char *a = “Name”
    in front of a shows pointer declaration. The complier asks to place to hold the pointer. Memory address will given the name ‘a’ and it points to the array of seven character.

3) What is the difference between malloc() and calloc()?
     The two functions mainly is to allocate memory and they are commonly called as memory managers.
     Malloc()  :- Malloc function take one argument
     Calloc()  :- Calloc function take two argument in a time. The bits in the allocated space are initialized to zero.

4) When should a type cast not be used?
    Program which uses const declaration should not override using type cast. This will cause the program not to run sucessfuly. Type cast cannot be used to turn pointer from one data type to another.

5) When is a switch statement better than multiple if statements?
    Switch statement is better used when it required to check more then one condition with the same variable. A switch statement check the condition only ones.

6) Define and explain scanf () function?         
   Scanf() function get the input from the user. It contains two argument.
   First argument: - specify the datatype
   For example: - %f This tells that the value will be in floating point
   Second argument: - name in which the data to be stored
   For example: -  &f1 the entered value is stored in f1.

7) Explain ‘variable scope’, ‘local scope’ and ‘global scope’ ?
    Any variable declared inside the function are said to be local variable.  These variable have meaning only within the function. Any variable declared outside the function are said to be global variable
    Scope of the variable: - the extent to which a variable is accessible is said to be scope of the variable.

8) What are signed variables?
    When a variable is initialized as integer, it can take positive or negative this is called as signed variables. Range of value that the variable can hold depend on the system.


9) What is operator precedence?
    Operator precedence, tells the order in which the c complier executes a expression. It uses the BODMAS rule                     
Brackets first
Orders (ie Powers and Square Roots, etc.)
Division and Multiplication (left-to-right)
Addition and Subtraction (left-to-right)

10) What is stack?
 Stack operates under the rule of last in, first out. It contains two basic operations Pop and push. A stack can hold any data type. Stack doesn’t perform flexible operation.

11) Explain about the functions strcat() ?
  Strcat() function is used to concatenate the strings. It appends a copy of the string in the source to the destination location
  For example:- strcat(str, “C”)
  Strcat(str, “programming”) 
  Output :- C programming

12) Explain strcmp()?
    Strcmp() function, compares to string character by character if any mismatch occurs then it will return the difference between the non matching value in ASCII code else if two strings compared till the end and they are same, then it return the value zero.

13) Difference between union and structure?
    Union and structure groups different variables together. UNION treats different variable with same memory space whereas structure uses different space for different variable.    

14) What is Register variable?
      Register variable are automatic variable. Register variable stores the data in the CPU. Storing and retrieval of data are quiet easy. Variables that are used repeatedly in the program can be stored as register variable for easy storage and retrieval. 

15) State some significant uses of arrays in C programming?
      Elements in a array are for char data type and can store single character in each element. The significant use of array is that the ability to store the strings as text.
16) What is heap?
      Heap allocates memory for malloc(), realloc and calloc. It is more flexible then stack.

17) What is memory leak?
      An allocated memory which is no longer needed but the memory space is not deallocated.
18) What are the basic data types in C?
      Four data types in C
         Int,float, char,double.

19) List any two format specifiers?
        %d can hold integer whole number.
        %c can hold single character value.

20) Define and explain about! Operator?
       It is a unary operator which is used before single operator. The not operator return the inverse value. It is used in programming which require to change the value of the variable.

21) What is static variable?
        Static variable are constant variable whose value remain the same throughout the program. Static variable are instant variable

22) How can you determine the size of an allocated portion of the memory?

        The malloc or free implementation would determine the size of the memory easily.

23) Why do we use structure?
      Structures are used for various purpose
          o Use of structure variable
          o To develop individual array.

24) Define these functions fopen(), fread(), fwrite() and fseek()?
      Fopen():- function to open a file, the pointer points to the first record in the file.
       Fread():- it reads the file were the pointer is pointing.
      Fseek():- This function enables to move from one record to another.
      Fwrite:- This function write data in the file were the pointer is pointing.

25) What are logical operators in C?
      Logical operators in C are AND and OR operator.
      AND denoted by && for example exp1&& exp2
      OR denoted by || for example exp1||exp2

 ---------------------------------------------------------------------------------
Posted By Sundeep aka SunTechie

Sundeep is a Founder of Youth Talent Auzzar, a passionate blogger, a programmer, a developer, CISE and these days he is pursuing his graduation in Engineering with Computer Science dept.
Add Sundeep as a Friend on 

                        

TCS new pattern Question 2013

Posted on:
tags: , , , , , , , ,

My name is PREET.But my son accidentally types the by interchanging a pair of letters in my name.What is the probability that despite this interchange, the name remains unchanged? a.5% b.20% c.25% d.12.5%
Ans:
10%

there are 10 possible pairs

out of which 1 will not change my name.

so probability that name remains unchanged = 1/10 = 10%


Roy is now 4 year older than Erik and half of that amount than Lewis.If in two years Roy will be twice as old as Erick,then in two year what would be Roy age multiplied by Lewis age??

Ans:ans is 48
firstly two equation from 1st sentence ..
suppose roy=x, erik=y, lewis=z
so x=y+4....(1)
2nd is x=z+2...(2) (Roy is now 4 year older than Erik and half of that amount than Lewis so 4/2=2)
also after 2 years erik and roy relation wil b
x+2=2(y+2).. (3)
so put this into 1st equ. u will get y=2..
and then x=6,z=4(by substituting other)
nw asking multiplication after two years of roy n lewis is (6+2)*(4+2)=48..

a man cut small cubes of 3 cubic cms each. Which he joined to form a cube wit 10 cubes length, 3 cubes in depth and 3 cubes wide. How many more small cubes does she require to form a perfect cube?

 Ans:
At present, the number of cubes used are 10*3*3=90. For a perfect cube, the cube should be 10 cubes length, 10 cubes in depth, and 10 cubes wide, i.e. 10*10*10=1000. So, additional number of cubes required is 1000-90= 910

one person has no siblings and says,"the guy in the photo is the only son of my fathers's son". what is the relation of the guy to the person

Ans:
His own son.


in a shopping mall with staff of 5 members, the average is 45.After 5 years a person joined them and the average is again 45. what is the age of 6th person?

Ans:
Since the average age is 45 yrs for the 5 members.
sum total of their ages = 45 X 5=225 yrs.
after 5 years, sum total of their ages = 225 + ( 5 X 5 ) = 250 yrs
now , let x be the age of the 6th person, so
the sum total of age is now = (250 + x ) yrs.
given the average is 45 yrs.
so,
( 250 + x )/ 6 = 45
or, x = 20 yrs.
so, the age of the 6th person is 20 years.

49 members attend the party.in that 22 are males,17 females.the shake hands between males,females,male,female.total 12 people given shake hands.how many such kinds of such shake hands are possible?

If you mean only 12 persons shook hands .
then 12C2 = 66 possible shake hands

what is the reminder when 6^17+17^6 is divided by 7?

First break the sum into two parts..
(i) 6^17 (ii) 17^6

sol-(i)- By remainder theorem there are always two remainders for any number, i.e. one is in negative and another is positive. In this case when we divide 6 by 7 we will get two remainders that is 6 and (-1). We can take any of these but for simplicity we will take (-1) is the remainder. Now (-1)^17 = -1.

sol-(ii)-- we have 17^6.. Now. 17^6 /7 = 3^6/7= (3^3)^2/7 = 27^2/7 = (-1)^2/7 = 1 is the remainder.

On adding case -(i) and (ii)... we will get final remainder = 0.

or

1   6^17 mod 7=(7-1)^17 mod 7
so 7^17 divide by 7 and remainder will 0,so we only take (-1)^17 mod 7=-1

2) 17^6 mod 7=(7*2+3)^6
so now (7*2)^17 divide by 7 and remainder will 0,so we only take (3)^6 mod 7=
729 mod 7=1
now add (1)+(2)
-1+1=0(ans)

What is the greatest possible positive integer n if 8^n divides (44)^44 without leaving a remainder?
a)14 b)28 c)29 d)15

Ans:
44^44 = 2^88 *11^44
= 8^29 * 2 * 11^44
so ans is 29

Complete the series 2, 7, 24, 77,__
Ans: 240

Ans:
(1st no.*3)+1=(2*3)+1=7
(2nd no.*3)+3=(7*3)+3=24
(3rd no.*3)+3=(24*3)+5=77
(4th no.*3)+1=(77*3)+7=238
or
ist*12=3rd 2*12=24
2nd*11=4th 7*11=77
3rd*10=5th 24*10=240
or
(2*3)+1=7
(7*3)+3=24
(24*3)+5=77
so ans is (77*3)+7=240

 

There is a circular pond and there is a road around the pond. The road is 4ft wide. The area of the pond is 11/25 of the area of the road. What is the radius of the pond?


Ans:let radius of pond=r
then,radius of road=r+4
since area of pond=11/25(area of road)
pi r^2=11/25 pi[(r+4)^2-r^2]
after solving this equa we get
25r^2-88r-176=0
r=4.94

There are two container. The volume of the second container is twice than the first. Half of the first cont. is filled with Wine & The one quarter of the second container is filled with wine. Now the remaining of the both container is filled with water. There is a third container which is enough to have the total liquid of the first two containers. What will be the ratio of the total volume and wine of the third container? Answer will be 1:3

Ans:consider A(first container)=100 for A wine filled half 100/2= 50
consider B(second container)=200 for B wine filled 1/4(200)=50
this two container mixed in 3rd container let as C=300
the ratio of wine to the volume of C is 100/300=1/3(1:3)

---------------------------------------------------------------------------------
Posted By Sundeep aka SunTechie

Sundeep is a Founder of Youth Talent Auzzar, a passionate blogger, a programmer, a developer, CISE and these days he is pursuing his graduation in Engineering with Computer Science dept.
Add Sundeep as a Friend on 


TCS New Pattern MOCK TEST for 2012-13 batch

Posted on:
tags: , , , , ,

TCS MOCK TEST 2



1.1/3 of a number is 6 more than 1/6 of that number then what is the number?
(a) 12
(b) 36
(c) 24
(d) 48

2.The pace length P is the distance between the rear of two consecutive footprints. For men, the formula n/P = 180 gives an approximate relationship between n and P where, n = number of steps per minute and P = pace length in meters. Bernard knows his pace length is 120 cm. The formula applies to Bernard’s walking. Calculate Bernard’s walking speed in kmph.
(a) 236.16
(b) 8.78
(c) 15.56
(d) 23.62

3.The IT giant Tirnop has recently crossed a head count of 150000 and earnings of $7 billion. As one of the forerunners in the technology front, Tirnop continues to lead the way in products and services in India. At Tirnop, all programmers are equal in every respect. They receive identical salaries and also write code at the same rate. Suppose 24 such programmers take 24 minutes to write 24 lines of code in total, how long will it take 72 programmers to write 72 lines of code in total?
(a) 12
(b) 24
(c) 6
(d) 72

4.A sheet of paper has statements numbered from 1 to 40. For each value of n from 1 to 40, statement n says “Exactly n of the statements on this sheet are true." Which statements are true and which are false? (a) All statements are false. (b) The odd numbered statements are true the even numbered are false. (c) Second last statement is true and the remaining statements are false. (d) The even numbered statements are true and the odd numbered are false.

5.Alok and Bhanu play the following min-max game. Given the expression N = 25 + X + Y – Z, where X, Y and Z are variables representing single digits (0 to 9), Alok would like to maximize N while Bhanu would like to minimize it. Towards this end, Alok chooses a single digit number and Bhanu substitutes this for a variable of her choice (X, Y or Z). Alok then chooses the next value and Bhanu, the variable to substitute the value. Finally Alok proposes the value for the remaining variable. Assuming both play to their optimal strategies, the value of N at the end of the game would be
(a) 43
(b) 16
(c) 36
(d) 34

6.A sheet of paper has statements numbered from 1 to 40. For each value of n from 1 to 40, statement n says “At least n of the statements on this sheet are true." Which statements are true and which are false? (a)First half of the statements are true and the rest are false. (b) The odd numbered statements are true the even numbered are false. (c) First half of the statements are false and the rest are true. (d) The even numbered statements are true and the odd numbered are false.

7.10 suspects are rounded by the police and questioned about a bank robbery. Only one of them is guilty. The suspects are made to stand in a line and each person declares that the person next to him on his right is guilty. The rightmost person is not questioned. Which of the following possibilities are true? A) All suspects are lying. B) The leftmost suspect is guilty. C) Rightmost suspect is guilty.
(a) A only
(b) A and B
(c) B only
(d) B and C

8.The citizens of planet nigiet are 6 fingered and have thus developed their decimal system in base 6. A certain street in nigiet contains 1000 (in base 6) buildings numbered 1 to 1000. How many 3s are used in numbering these buildings?
(a) 108
(b) 192
(c) 54
(d) 102

9.One the Planet, Oz, there are 8 days in a week – Sunday to Saturday and another day called Oz day. There are 36 hours in a day and each hour has 90 minutes while each minute has 60 seconds. As on earth, hour hand covers the dial twice every day. Find the approximate angle between the hands of clock on Oz when the time is 14.40 a.m.
(a) 83
(b) 74
(c) 129
(d) 65

10.On planet zorba, a solar blast has melted the ice caps on its equator. 8 years after the ice melts, tiny planetoids called echina start growing on the rocks. Echina grows in the form of a circle and the relationship between the diameter of this circle and the age of echina is given by the formula d = 2 * √ (t - 8) for t ≥ 8 where d represents the diameter in mm and t the number of years since the solar blast. Jegan recorded the radius of some echina at a particular spot as 4 mm. How many years back did the solar blast occur?
(a) 18
(b) 12
(c) 16
(d) 24

11.It is dark in my bedroom and I want to get two socks of the same colour from my drawer, which contains 26 red and 24 blue, 34 brown socks. How many socks do I have to take from the drawer to get at least two socks of the each colour?
(a) 6
(b) 74
(c) 61
(d) 62

12.For the FIFA world cup, Paul the octopus has been predicting the winner of each match with amazing success. It is rumoured that in a match between 2 teams A and B, Paul picks A with the same probability as A's chances of winning. Let’s assume such rumours to be true and that in a match between Ghana and Bolivia, Ghana the stronger team has a probability of 5/6 of winning. What is the probability that Paul will correctly pick the winner of the Ghana-Bolivia game?
(a) 0.72
(b) 0.50
(c) 0.64
(d) 0.83

13.Given 3 lines in the plane such that the points of intersection form a triangle with sides of length 19, 19 and 19, the number of points equidistant from all the 3 lines is
(a) 1
(b) 0
(c) 4
(d) 2

14.66 people {a1, a2,..., a66} meet and shake hands in a circular fashion. In other words, there are totally 36 handshakes involving the pairs, {a1, a2}, {a2, a3}, ..., {a65, a66}, {a66, a1}. The size of the smallest set of people such that the rest have shaken hands with at least one person in the set is
(a) 22
(b) 33
(c) 65
(d) 11

15.The IT giant Tirnop has recently crossed a head count of 150000 and earning of $7 billion. As one of the forerunners in the technology front, Tirnop continues to lead the way in products and services in India. At Tirnop, all programmers are equal in every respect. They receive identical salaries and also write code at the same rate.Suppose 16 such programmers take 16 minutes to write 16 lines of code in total, how many lines of code can be written by 96 programmers in 96 minutes?
(a) 16
(c) 432
(d) 96
(b) 576

16.Ferrari S.p.A. is an Italian sports car manufacturer based in Maranello, Italy. Founded by Enzo Ferrari in 1928 as Scuderia Ferrari, the company sponsored drivers and manufactured race cars before moving into production of street-legal vehicles in1947 as Ferrari S.p.A. Throughout its history, the company has been noted for its continued participation in racing especially in Formula One where it has enjoyed great success. Rohit once bought a Ferrari. It could go 3 times as fast as Mohit’s old Mercedes. If the speed of Mohit’s Mercedes is 33 km/hr and the distance travelled by the Ferrari is 909 km, find the total time taken in hours for Rohit to drive that distance.
(a) 9.18
(b) 10.18
(c) 9
(d) 99

17.Anoop managed to draw 6 circles of equal radii with their centers on the diagonal of a square such that the two extreme circles touch two sides of the square and each middle circle touches two circles on either side. Find the ratio of the side of the square to the radius of the circles. Assume Ö2 is 1.4.
(a) 9 : 1
(b) 6.2 : 1
(c) 10.4 : 1
(d) 7.6 : 1
18.A hare and a tortoise race along a circle of 100 yards diameter. The tortoise goes in one direction and the hare in the other. The hare starts after tortoise has covered 1/5 of its distance and that too leisurely. The hare and tortoise meet when the hare has covered only 1/4 of the distance. By what factor should the hare increase its speed so as to tie the race?
(a) 8
(b) 37
(c) 45
(d) 6.6

19.There are two boxes, one containing 21 red balls and the other containing 25 green balls. You are allowed to move the balls between the boxes so that when you choose a box at random and a ball at random from the chosen box, the probability of getting a red is maximized. This maximum probability is
(a) 0.5
(b) 0.63
(c) 0.72
(d) 0.48

20.Alok and Bhanu play the following min-max game. Given the expression N = 32 + X* (Y – Z), where X, Y and Z are variables representing single digits (0 to 9), Alok would like to maximize N while Bhanu would like to minimize it. Towards this end, Alok chooses a single digit number and Bhanu substitutes this for a variable of her choice (X, Y or Z). Alok then chooses the next value and Bhanu, the variable to substitute the value. Finally Alok proposes the value for the remaining variable. Assuming both play to their optimal strategies, the value of N at the end of the game would be
(a) 113
(b) 32
(c) -49
(d) 50

21.A sheet of paper has statements numbered from 1 to 40. For each value of n from 1 to 40, statement n says "At most n of the statements on this sheet are true." Which statements are true and which are false? (a) All statements are true (b) The odd numbered statements are true the even numbered are false (c) The first half of the statements are true and the remaining statements are false (d) The even numbered statements are true and the odd numbered are false

22.After a typist writes 25 letters and addresses 25 envelopes, she inserts the letters randomly into the envelopes (1 letter per envelope). What is the probability that exactly 1 letter is inserted in an improper envelope?
(a) 23/25
(b) 0
(c) 2/25
(d) 1

23.There are two water tanks A and B, where A is much smaller than B. While water fills at the rate of one liter every hour in A, it gets filled up like 10, 20, 40, 80, liters….., in tank B. (At the end of first hour, B has 10 liters, second hour it has 20, and so on) If tank B is 1/64 filled after 17 hours, what is the total duration required to fill it completely?
(a) 6 hours
(b) 24 hours
(c) 22 hours
(d) 23 hours

24.You have a jar containing water absorbing marbles which will take 21 hours to set completely when fixed with white cement. There are 50 red marbles, 52 blue marbles and 63 black marbles. The jar is kept inside a dark room. What is the minimum number of marbles that you need to pick to make sure that you have a pair of marbles in each color?
(a) 117
(b) 98
(c) 120
(d) 114

25.A circular dartboard of radius 1 foot is at a distance of 20 feet from you. You throw a dart at it and it hits the dartboard at some point Q in the circle. What is the probability that Q is closer to the center of the circle than the periphery?
(a) 0.25
(b) 0.50
(c) 0.75
(d) 0.3333

26.A hollow cube of size 5 cm is taken with a thickness of 1 cm. It is made of smaller cubes of size 1 cm. If only 2 faces of the outer surface of the cube are painted, totally how many faces of the smaller cubes remain unpainted?
(a) 210
(b) 465
(c) 450
(d) 538


27.Planet fourfi resides in 4-dimensional space and thus the currency used by its residents are 3-dimensional objects. The rupee notes are cubical in shape while their coins are spherical. However, the coin minting machinery lays out some stipulations on the size of the coins.
- The diameter of the coins should be at least 256 mm and not exceed 4096 mm.
- Given a coin, the diameter of the next larger coin is at least 50% greater.
- The diameter of a coin must always be an integer.
You are asked to design a set of coins of different diameters with these requirements and your goal is to design as many coins as possible. How many coins can you design?
(a) 7
(b) 8
(c) 9
(d) 6

28.Alok is attending a workshop "How to do more with less" and today's theme is “Working with fewer digits”. The speakers discuss how a lot of miraculous mathematics can be achieved if mankind (as well as womankind) had only worked with fewer digits. The problem posed at the end of the workshop is “How many 7 digit numbers can be formed using the digits 1, 2, 3, 4, 5 (but with repetition) that are divisible by 4?” Can you help Alok find the answer?
(a) 5000
(b) 15625
(c) 2500
(d) 3179

29.Alice and Bob play the following coins-on-a-stack game. 20 coins are stacked one above the other. One of them is a special (gold) coin and the rest are ordinary coins. The goal is to bring the gold coin to the top by repeatedly moving the topmost coin to another position in the stack. Alice starts and the players take turns. A turn consists of moving the coin on the top to a position i below the top coin (0 ≤ i ≤ 20). We will call this an i-move (thus a 0-move implies doing nothing). The proviso is that an i-move cannot be repeated; for example once a player makes a 2-move, on subsequent turns neither player can make a 2-move. If the gold coin happens to be on top when it's a player's turn, then the player wins the game. Initially, the gold coin is the third coin from the top. Then (a) In order to win, Alice’s first move should be a 0-move. (b) In order to win, Alice’s first move should be a 1-move. (c) Alice has no winning strategy. (d) In order to win, Alice’s first move can be a 0-move or a 1-move

30.There are 5 pentagonal pyramid shaped bottles whose volumes are in geometric progression and there are 5 materials to make a perfume inside the bottle viz., Lilac, Balsamic, Lemon, Woody and Mimosaic. Also, all the faces of the pyramids are painted in different colours. To make a perfume that is in demand, the following conditions are to be followed: Lilac and Balsamic go together. Woody and Mimosaic go together. Woody and Balsamic never go together. Lemon can be added with any material. All of the following combinations are possible to make a perfume EXCEPT (a) Balsamic and Lilac (b) Woody and Lemon (c) Mimosaic and Woody (d) Mimosaic and Lilac

31.20 people meet and shake hands. The maximum number of handshakes possible if there is to be no “cycle” of handshakes is (A cycle of handshakes is a sequence of k people a1, a2, ……, ak (k > 2) such that the pairs {a1, a2}, {a2, a3}, ……, {ak-1, ak}, {ak, a1} shake hands)
(a) 19
(b) 18
(c) 20
(d) 21

32.There are 45 cans out of which one is poisoned. If a person tastes very little of this, he will die within 14 hours; so they decided to test it with mice. Given that a mouse dies in 24 hours and you have 24 hours in all to find out the poisoned can, how many mice are required to find the poisoned can?
(a) 44
(b) 29
(c) 6
(d) 5

33.Middle-earth is a fictional land inhabited by hobbits, elves, dwarves and men. The hobbits and elves are peaceful creatures who prefer slow, silent lives and appreciate nature and art. The dwarves and the men engage in physical games. The game is as follows. A tournament is one where out of the two teams that play a match, the one that loses get eliminated. The matches are played in different rounds, where in every round, half of the teams get eliminated from the tournament. If there are 9 rounds played in a knockout tournament, how many matches were played?
(a) 511
(b) 512
(c) 256
(d) 255


34.The IT giant Tirnop has recently crossed a head count of 150000 and earning of $7 billion. As one of the forerunners in the technology front, Tirnop continues to lead the way in products and services in India. At Tirnop, all programmers are equal in every respect. They receive identical salaries and also write code at the same rate.Suppose 12 such programmers take 12 minutes to write 12 lines of code in total. How many programmers will complete 96 lines in 96 minutes?
(a) 12
(b) 96
(c) 1152
(d) 32

35.Given a collection of points P in the plane, a 1-set is a point in P that can be separated from the rest by a line i.e. the point lies on one side of the line while the others lie on the other side. The number of 1-sets of P is denoted by n1 (P). The maximum value of n1(P) over all configurations P of 10 points in the plane is
(a) 5
(b) 10
(c) 9
(d) 9



---------------------------------------------------------------------------------
Posted By Sundeep aka SunTechie

Sundeep is a Founder of Youth Talent Auzzar, a passionate blogger, a programmer, a developer, CISE and these days he is pursuing his graduation in Engineering with Computer Science dept.
Add Sundeep as a Friend on 
◘ >