You are on page 1of 10

Tech Mahindra Technical Paper 1

C-Test Paper 1. #include * What is wrong in the following problem main() int i!"# " $ 1%# i $ "&& - "&&# printf('(d (d'! i!")# ) ans* %! 1+ +.#include * What is the output of the following problem main() int "# for("$%#",-#"&&) foo()# ) foo() static int i $ 1%# i&$1%# printf('(d.n'!i)# ) /* 0ut put is (***since static int is used i 1alue is retained between * +% function calls ) * -% * 2% * / -.#include #include #include /* This is as3ed in PC4 5omba6 wal3-in-inter1iew * What is wrong in the following code */ main() char *c# c $ '7ello'# printf('(s.n'! c)# )

/*ans*- 7ello! The code is successfull6 running */ 2. #include /* This problem is gi1en in PC4 50859: wal3-in-inter1iew. * What is the final 1alue of i and how man6 times loop is * ;<ecuted = */ main() int i!"!3!l!lc$%# /* the input is gi1en as 1+-2 >?@ */ printf(';nter the number string*,1+-2 >?@ .n')# scanf('(+d(d(1d'!Ai!A"!A3)# for(#3#3--!i&&) for(l$%#l printf('(d (d.n'!i!l)#) printf('B00P4$ (d.n'! lc-1)# ) /* 9ns* i $ 1?! and loop is e<ecuted for 1?C times */ >.#include /* This is gi1en in PC4 5omba6 wal3-in-inter1iew */ /* What is the output of the following program */ main() union int a# int b# int c# ) u!1# u.a $ 1%# u.b $ +%# printf('(d (d .n'!u.a!u.b)# ) /* 9ns * The latest 1alue assigned to an6 of the union member will be present in the union members so answer is +% +% */ ?.#include main() float i! "# scanf('(f (f'! Ai! A")# printf('(.+f (.-f'! i! ")# ) /9ns*- 1+-.-2 -. +-2 */

@.#include /* This is gi1en in PC4 5omba6 wal3-in-inter1iew * What is the out put of the following problem = */ main() char *str $ '1+-2>'# printf('(c (c (c.n'! *str! *(str&&)! *(str&&))# ) /* 9ns* Dt is not 1 + * 5ut it is - + 1 Wh6 == */ E.#include /* This problem is as3ed in PC4 5omba6 Wal3-in-inter1iew * Write a macro statement to find ma<imum of a!b */ #define ma<(a!b) (ab)=a*b main() int a!b# a$-# b$2# printf('(d'!ma<(a!b))# ) /* 9ns is 1er6 simple the coding is "ust for testing it and output is 2 */ F C.#include /* This problem is as3ed in PC4 5omba6 * What is the output of the following coding */ main() int len$2# char *st$'1+-2>?@E'# st $ st -len# printf('(c.n'!*st)# ) /* 9ns * Dt will print some "un3 1alue */ F 1%.#include main() func(1)# )

func(int i) static char *str $ '0ne'!'Two'!'Three'!'Gour')# printf('(s.n'!strHi&&I)# return# ) /* 9ns*- it will gi1e warning because str is pointer to the char but it is initialiJed with more 1alues if it is not considered then the answer is Two */ 11. #include main() int i# for (i$1#i,1%%# i&&) printf('(d (%<.n'!i!i)# ) /* 9ns*- i is from 1 to CC for the first format! for the second format 1toC! ato f! 1% to 1C!1ato1f! +% to +C! etc */ 1+.#include /* This problem is as3ed in PC4 5omba6 wal3-in-inter1iew * Dn the following code please write the s6nta< for * assing a 1alue of 1% to field < of s and idKno 1%1 of s */ struct int <# int 6# union int idKno# char *name# )b# )s!*st# main() st $ As# st-<$1%# st-b.idKno $ 1%1# printf('(d (d.n'!s..<!s.b.idKno)# ) /* 9ns* The answer is st-<$1%# * st-b.idKno$1%1# */ 1-.#include /* This problem was as3ed in PC4 5omba6 in a wal3-in-inter1iew * Write a recursi1e function that calculates * n * (n-1) * (n-+) * ....... + * 1 */

main() int factorial(int n)# int i!ans# printf('.n ;nter a Lumber*')# scanf('(d'!Ai)# ans $ factorial(i)# printf('.nGactorial b6 recursion $ (d.n'! ans)# ) int factorial(int n) if (n ,$ 1) return (1)# else return ( n * factorial(n-1))# ) F 12.#include /* This problem is as3ed in PC4 5omba6 wal3-in-inter1iew * What is the output of the following problem */ main() int "!ans# " $ 2# ans $ count(2)# printf('(d.n'!ans)# ) int count(int i) if ( i , %) return(i)# else return( count(i-+) & count(i-1))# ) /* Dt is showing -1E as an answer */ 1>.#include main() int i$2# if(i$%) printf('statement 1')# else printf('statement +')# ) /* statement + */ This is pcsb paper.

1. #include * What is wrong in the following problem main() int i!"# " $ 1%# i $ "&& - "&&# printf('(d (d'! i!")# ) ans* %! 1+ +.#include * What is the output of the following problem main() int "# for("$%#",-#"&&) foo()# ) foo() static int i $ 1%# i&$1%# printf('(d.n'!i)# ) /* 0ut put is (***since static int is used i 1alue is retained between * +% function calls ) * -% * 2% * / -.#include #include #include /* This is as3ed in PC4 5omba6 wal3-in-inter1iew * What is wrong in the following code */ main() char *c# c $ '7ello'# printf('(s.n'! c)# ) /*ans*- 7ello! The code is successfull6 running */ 2. #include /* This problem is gi1en in PC4 50859: wal3-in-inter1iew. * What is the final 1alue of i and how man6 times loop is * ;<ecuted =

*/ main() int i!"!3!l!lc$%# /* the input is gi1en as 1+-2 >?@ */ printf(';nter the number string*,1+-2 >?@ .n')# scanf('(+d(d(1d'!Ai!A"!A3)# for(#3#3--!i&&) for(l$%#l printf('(d (d.n'!i!l)#) printf('B00P4$ (d.n'! lc-1)# ) /* 9ns* i $ 1?! and loop is e<ecuted for 1?C times */ >.#include /* This is gi1en in PC4 5omba6 wal3-in-inter1iew */ /* What is the output of the following program */ main() union int a# int b# int c# ) u!1# u.a $ 1%# u.b $ +%# printf('(d (d .n'!u.a!u.b)# ) /* 9ns * The latest 1alue assigned to an6 of the union member will be present in the union members so answer is +% +% */ ?.#include main() float i! "# scanf('(f (f'! Ai! A")# printf('(.+f (.-f'! i! ")# ) /9ns*- 1+-.-2 -. +-2 */ @.#include /* This is gi1en in PC4 5omba6 wal3-in-inter1iew * What is the out put of the following problem = */

main() char *str $ '1+-2>'# printf('(c (c (c.n'! *str! *(str&&)! *(str&&))# ) /* 9ns* Dt is not 1 + * 5ut it is - + 1 Wh6 == */ E.#include /* This problem is as3ed in PC4 5omba6 Wal3-in-inter1iew * Write a macro statement to find ma<imum of a!b */ #define ma<(a!b) (ab)=a*b main() int a!b# a$-# b$2# printf('(d'!ma<(a!b))# ) /* 9ns is 1er6 simple the coding is "ust for testing it and output is 2 */ F C.#include /* This problem is as3ed in PC4 5omba6 * What is the output of the following coding */ main() int len$2# char *st$'1+-2>?@E'# for(i$%# i,?# i&&) st $ st -len# printf('(c.n'!*st)# ) /* 9ns * Dt will print some "un3 1alue */ F 1%.#include main() func(1)# ) func(int i) static char *str $ '0ne'!'Two'!'Three'!'Gour')# printf('(s.n'!strHi&&I)# return#

) /* 9ns*- it will gi1e warning because str is pointer to the char but it is initialiJed with more 1alues if it is not considered then the answer is Two */ 11. #include main() int i# for (i$1#i,1%%# i&&) printf('(d (%<.n'!i!i)# ) /* 9ns*- i is from 1 to CC for the first format! for the second format 1toC! ato f! 1% to 1C!1ato1f! +% to +C! etc */ 1+.#include /* This problem is as3ed in PC4 5omba6 wal3-in-inter1iew * Dn the following code please write the s6nta< for * assing a 1alue of 1% to field < of s and idKno 1%1 of s */ struct int <# int 6# union int idKno# char *name# )b# )s!*st# main() st $ As# st-<$1%# st-b.idKno $ 1%1# printf('(d (d.n'!s.<!s.b.idKno)# ) /* 9ns* The answer is st-<$1%# * st-b.idKno$1%1# */ 1-.#include /* This problem was as3ed in PC4 5omba6 in a wal3-in-inter1iew * Write a recursi1e function that calculates * n * (n-1) * (n-+) * ....... + * 1 */ main() int factorial(int n)# int i!ans#

printf('.n ;nter a Lumber*')# scanf('(d'!Ai)# ans $ factorial(i)# printf('.nGactorial b6 recursion $ (d.n'! ans)# ) int factorial(int n) if (n ,$ 1) return (1)# else return ( n * factorial(n-1))# ) F 12.#include /* This problem is as3ed in PC4 5omba6 wal3-in-inter1iew * What is the output of the following problem */ main() int "!ans# " $ 2# ans $ count(2)# printf('(d.n'!ans)# ) int count(int i) if ( i , %) return(i)# else return( count(i-+) & count(i-1))# ) /* Dt is showing -1E as an answer */ 1>.#include main() int i$2# if(i$%) printf('statement 1')# else printf('statement +')# ) /* statement + */

You might also like