0% found this document useful (0 votes)
57 views

Technical Aptitude

The document contains technical questions related to C programming fundamentals. It includes questions on errors in code snippets, output of code snippets, preprocessor directives, data types, operators, control flow, functions, arrays and pointers. The questions test knowledge of basic C syntax, semantics and programming concepts.

Uploaded by

Santosh Sandy
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Technical Aptitude

The document contains technical questions related to C programming fundamentals. It includes questions on errors in code snippets, output of code snippets, preprocessor directives, data types, operators, control flow, functions, arrays and pointers. The questions test knowledge of basic C syntax, semantics and programming concepts.

Uploaded by

Santosh Sandy
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

Technical Aptitude

Subject: C Fundamentals
1. Point out the type of error, if any in the following program.
main( )
{
extern int i ;
i = 20 ;
printf ( "%d", sizeof ( i ) ) ;
}
a) Compile Time Error b) Run Time Error c) No Error d) Linker Error
2. Consider the following program segment.

main( )
{
int a = 5, b = 10 ;
P(a);
P(b);
}

Define the macro P such that the output of the program comes out to be a = 5 b = 10

Predict the output or error(s) for the following:


3. void main()
{
int const * p=5;
printf("%d",++(*p));
}
4. main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
5. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
6. main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
7. What will be the output of the following code?

void main ()
{
int i = 0 , a[3] ;
a[i] = i++;
printf (%d",a[i]) ;
}
8. Predict the output or error
#define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
10. enum colors {BLACK,BLUE,GREEN}
main()
{
printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1);
}

11. main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}

12. main()
{
int a=3, b = 4, c, d;
c = a,b;
d = (a,b);
printf(%d %d,c,d);
}
13. What will be the output of the following program :
void main()
{
char str[]="C For Swimmers";
printf("%d",-sizeof(str));
}
(a)14 (b)Compile-Time Error (c)-15 (d)-14
14. What will be the output of the following program :
void main()
{
printf("%d",!(100==100)+1);
}
(a)100 (b)0 (c)1 (d)2
15. What will be the output of the following program :
void main()
{
printf("%d %d %d",5,!5,25-!25);
}
(a)5 10 22 (b)5 5 25 (c)5 0 25 (d)5 1 24
16) What will be the output of the following program:
int main()
{
int a=500,b=100,c=30,d=40,e=19;
a+=b-=c*=d/=e%=5;
printf("%d %d %d %d %d",a,b,c,d,e);
}
(a)500 100 30 40 4 (b)Run-Time Error (c)700 200 300 10 4 (d)300 -200 300 10 4
17) What will be the output of the following program:
void main()
{
int a,b,c;
scanf("%1d %2d %3d",&a,&b,&c);
printf("Sum=%d",a+b+c);
}
[NOTE : THE USER INPUT IS :123456 44 544]
(a)Sum=480 (b)Sum=594 (c)Sum=589 (d)None of these
18. What happens when the following program is executed?
void main()
{
char line[80];
scanf("%[^1234567890\n]",line);
}
(a) Accepts the string that contains DIGITS only.
(b) Accepts the string that contains DIGITS and NEWLINE characters.
(c) Accepts the string that contains anything other than the DIGITS and NEWLINE
characters.
(d)None of these

19. What happens when the following program is executed :


void main()
{
char line[80];
scanf("%[^*]",line);
}
(a) Accepts the string that contains DIGITS & ALPHABETS only.
(b)Accepts the string that contains * or asterisk characters only.
(c)Accepts the string that contains anything other than the * or asterisk character.
(d)None of these

20.

void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}

a) 8 b) 7 c) 6 d)5
Answer:
1) Linker Error : Undefined Symbol i.

By 'extern int i' we mean that the variable i has been declared before the main( )
function or in some other file. Here i is not declared before main( ) function, therefore it
is assumed that i has been defined in some other file. Since the file is not included by
#include, hence the Linker Error.

2) #define P( x ) printf( #x " = %d\n", x ) ;

3) Compiler error: Cannot modify a constant value.

4) mmmm
aaaa
nnnn
Explanation:
s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea.
Generally array name is the base address for that array. Here s is the base address. i is the
index number/displacement from the base address. So, in directing it with * is same as
s[i]. i[s] may be surprising. But in the case of C it is same as s[i].

5) I hate U
Explanation:
For floating point numbers (float, double, long double) the values cannot
be predicted exactly. Depending on the number of bytes, the precession with of the value
represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9
with less precision than long double.

6) 54321
Explanation:
When static storage class is given, it is initialized once. The change in the
value of a static variable is retained even between the function calls. Main is also treated
like any other ordinary function, which can be called recursively.

7) A garbage value.
Explanation:
In the statement a[i] = i++; the value of the variable i would get assigned first to
a[i] i.e. a[0] and then the value of i would get incremented by 1. Since a[i] i.e. a[1] has
not been initialized, a[i] will have a garbage value.
8) 100
Explanation:
Preprocessor executes as a seperate pass before the execution of the compiler. So
textual replacement of clrscr() to 100 occurs.The input program to compiler looks like
this :
main()
{
100;
printf("%d\n",100);
}
100; is an executable statement but with no action. So it doesn't give any problem

9) 0..1..2
Explanation:
enum assigns numbers starting from 0, if not explicitly defined.

11. 1
Explanation:
Scanf returns number of items successfully read and not 1/0. Here 10 is given as
input which should have been scanned successfully. So number of items read is 1.

12. 3 4

13. d
14. c
15. c
16. d
17. a
18. c
19. c
20. c

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy