TCS Input and Output
TCS Input and Output
#include <stdio.h>
void main()
printf("includehelp.com\rOK\n");
printf("includehelp.com\b\b\bOk\n");
a) OK includehelp.ok
b) OK includehelp.okm
c) includehelp.com includehelp.okm
d) OKcludehelp.com includehelp.okm
Explanation: OKcludehelp.com
includehelp.Okm
/r is an escape sequence which means carriage return. Carriage return takes back the cursor to the
leftmost side in a line.
Thus in the statement printf("includehelp.com\rOK\n");
First "includehelp" is printed ( not still displayed) then cursor moves to leftmost position ("i" here) and
starts printing "OK" which results in overwriting of first two characters of "includehelp". Thus the
final output is "OKcludehelp.com" and then cursor moves to next line due to character feed \n.
In the second statement /b escape character is used which is equivalent to backspacing the cursor.
Overwrite also took place here due to three backspaces.
#include <stdio.h>
void main(){
printf("%d",c);
}
a) 34
b) 290
c) Garbage
d) Error
Explanation: 290 is beyond the range of unsigned char. Its corresponding value printed is: (290 %
(UINT_MAX +1) where UINT_MAX represents highest (maximum) value of UNIT type of variable.
#include <stdio.h>
void main(){
int a=0;
a=5||2|1;
printf("%d",a);
}
a) 1
b) 7
c) 8
d) 9
Explanation:
5 || 2 | 1 is actually 5 || (2 |1)
Now
2= 0000 0010
1= 0000 0001
2|1= 0000 0011=3
5 || 3 returns true as both are nonzero
Thus a=1
#include <stdio.h>
int main(){
float a=125.50;
int b=125.50;
char c='A';
printf("%d,%d,%d\n",sizeof(a),sizeof(b),sizeof(125.50));
printf("%d,%d\n",sizeof(c),sizeof(65));
return 0;
}
a) 4,4,4 1,4
b) 4,4,8 1,4
c) 4,4,4 1,1
d) 4,4,8 1,4
Explanation:
sizeof(a)= 4 bytes (float), sizeof(b)=4 bytes(int...in Visual studion, 2 in turboc), sizeof(125.50)=8 bytes
(125.50 will consider as double constant), sizeof(c)= 1 byte (character), sizeof(65) = 4 bytes ( 65 is an
integer ).
5. What will be the output of following program ?
#include <stdio.h>
int main(){
static char a;
static long b;
int c;
printf("%d,%d,%d",a,b,c);
return 0;
}
a) 0,0,0
b) Garbage,Garbage,Garbage
c) Garbage,Garbage,0
d) 0,0,Garbage
Explanation: Static variable always initialize with 0, and other one by garbage value.
N.B: output is compiler dependent
int main()
int ok=-100;
-100;
printf("%d",ok);
return 0;
}
a) 100
b) error
c) -100
d) 101
Explanation: -100 is evaluated and this does not effect the value of ok
7. What will be the output of following program ?
#include <stdio.h>
enum numbers
{
zero, one, two, three , four=3,five,six,seven=0,eight
};
void main()
{
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d",zero,one,two,three,four,five,six,seven,eight);
}
a) 0,1,2,3,3,4,5,0,1
b) 0,1,2,4,5,6,7,8,9
c) 0,1,2,3,3,1,2,3,4
d) 0,1,2,3,3,4,5,0,9
Explanation: -0,1,2,3,3,4,5,0,1
We have discussed that enum values starts with 0 (if we do not provide any value) and increase one by
one.
We are assigning 3 to four, then four will be 3, five will be 4 ... again we are assigning 0 to seven then
seven will be 0 and eight will be 1.
8. What will be the output of following program ?
#include <stdio.h>
int main(){
int a,b,c;
a=0x10; b=010;
c=a+b;
return 0;
}
a) Addition is =20
b) Addition is =24
c) Addition is = Garbage
d) Error
Explanation: - 0x10 is hex value it's decimal value is 16 and 010 is an octal value it's decimal value is 8,
hence answer will be 24.
#include <stdio.h>
int main()
{
int var=250;
printf("value of var = %d\n",var);
200+50;
"includehelp.com";
printf("%s\n","includehelp");
return 0;
200+50; and "includehelp.com"; are executable statements, will not give any error because there is no
action is performed by these statements.
#include <stdio.h>
int main()
int a=100;
printf("%d\n"+1,a);
printf("Value is = %d"+3,a);
return 0;
}
a) Error
b) 101,Value is = 103
c) due is = 100
d) 100 100
#include <stdio.h>
int main()
printf("value of ok = %d",ok);
return 0;
a) Declaration error
b) value of ok = 1000.
c) Linking error
d) value of ok = 0.
Explanation: extern keyword is used to extend the visibility of variables thus ok is declared and defined
memory though the statement extern int ok=1000; is outside main function.
#include <stdio.h>
int main()
int a=23;
;printf("%d",a);
return 0;
}
a) 23
b) Error
c) ;23;
d) ;23
#include <stdio.h>
int main()
int intVar=24;
printf("%d,%d",intVar,x);
return 0;
}
a) 24,24
b) 24,0
c) ERROR: illegal Initialization
d) Run time error
Explanation: You cannot assign a variable into static variable at the time of declaration.
#include <stdio.h>
int main()
int a=15;
float b=1.234;
printf("%*f",a,b);
return 0;
}
a) 1.234
b) 1.234000
c) 1.23400000
d) ERROR
Explanation: You can define width formatting at run time using %*, This is known as Indirect width
precision .
printf("%*f",a,b); is considered as "%15f", hence value of b is printed with left padding by 15.
15. Find the output of this program ?
#include <stdio.h>
int main()
float a,b;
a=3.0f;
b=4.0f;
printf("%.0f,%.1f,%.2f",a/b,a/b,a/b);
return 0;
}
a) 1,0.8,0.75
b) 0,0.7,0.75
c) 0,0.8,0.75
d) ERROR
16. Which is the valid identifier (variable name) to store student’s age?
a) int student-age;
b) int student_age;
c) int -age;
d) int &age;
Explanation: identifier name cannot start with a '-' or '&'
Explanation: we know that o is false and 1 is true. so coming to the main point the condition is:
if(1)
means if it is true
then print" hai " or else the "hello"
so the answer is option (2) hai
Explanation: In the above program output should (11,12) because it follows pre_increment