| [Q001] Determine which of the following are VALID
identifiers. If invalid, state the reason. |
(a)
sample1
(b) 5sample
(c) data_7
(d) return
(e) #fine
(f) variable
(g) 91-080-100
(h) name & age
(i) _val
(j) name_and_age
|
(a) VALID
(b) Invalid, since an identifier must begin with a letter or an underscore
(c) VALID
(d) Invalid, since return is a reserved word
(e) Invalid, since an identifier must begin with a letter or an underscore
(f) VALID
(g) Invalid, since an identifier must begin with a letter or an underscore
(h) Invalid, since blank spaces are not allowed
(i) VALID
(j) VALID |
|
|
| [Q002] Determine which of the following are VALID
character constants. If invalid, state the reason. |
(a) 'y'
(b) '\r'
(c) 'Y'
(d) '@'
(e) '/r'
(f) 'word'
(g) '\0'
(h) '\?'
(i) '\065'
(j) '\''
(k) ' '
|
(a) VALID
(b) VALID
(c) VALID
(d) VALID
(e) Invalid, since escape sequences must be written with a backward slash (i.e. \)
(f) Invalid, since a character constant cannot consist of multiple characters
(g) VALID (null-character escape sequence)
(h) VALID
(i) VALID (Octal escape sequence)
(j) VALID
(k) VALID |
|
|
| [Q003] Determine which of the following are VALID
string constants. If invalid, state the reason. |
(a) 'Hi Friends'
(b) "abc,def,ghi"
(c) "Qualification
(d) "4325.76e-8"
(e) "Don\'t sleep"
(f) "He said, "You\'re great"
(g) ""
(h) " "
(i) "Rs.100/-"
|
(a) Invalid, since a string constant must be enclosed in double quotation marks
(b) VALID
(c) Invalid, since trailing quotation mark is missing
(d) VALID
(e) VALID (single-quote escape sequence)
(f) Invalid, since the quotation marks and (optionally) apostrophe within the string cannot be expressed without the escape sequences.
(g) VALID
(h) VALID
(i) VALID |
|
|
| [Q004] Determine which of the following numerical
values are valid constants. If a constant is valid, specify whether
it is integer or real. Also, specify the base for each valid
integer constant. |
(a) 10,500
(b) 080
(c) 0.007
(d) 5.6e7
(e) 5.6e-7
(f) 0.2e-0.3
(g) 0.2e 0.3
(h) 0xaf9s82
(i) 0XABCDEFL
(j) 0369CF
(k) 87654321l
(l) 87654321
|
(a) Invalid, since illegal character(,)
(b) VALID
(c) VALID
(d) VALID
(e) VALID
(f) VALID
(g) Invalid, since illegal character(blank space)
(h) Invalid, since illegal character(s)
(i) VALID
(j) Invalid, since illegal characters (9, C, F), if intended as an octal constant.
(k) VALID
(l) VALID |
|
|
| [Q005] Determine which of the following
floating-point constants are VALID for the quantity (5 * 100000). |
(a) 500000
(b) 0.5e6
(c) 5E5
(d) 5e5
(e) 5e+5
(f) 500E3
(g) .5E6
(h) 50e4
(i) 50.E+4
(j) 5.0E+5
(k) All of the above
(l) None of these
|
| (k) All of the above |
|
|
| [Q006] What will be the output of the following
program : |
int main()
{
printf("%f",123.);
return(0);
}
|
(a)123
(b)Compile-Time Error
(c)123.00
(d)123.000000 |
| 123. is a valid double
value and it is equivalent to 123.000000 |
|
|
| [Q007] What will be the output of the following
program : |
int main()
{
printf("%d",sizeof(integer));
return(0);
}
|
(a)2
(b)Compile-Time Error
(c)4
(d)None of these |
| The data type 'integer'
doesn't exist. It should be 'int'. |
|
|
| [Q008] What will be the output of the following
program : |
int main()
{
char str[]="C For Swimmers";
printf("%d",sizeof str);
return(0);
}
|
(a)14
(b)Compile-Time Error
(c)15
(d)None of these |
| Length of the string 'C
For Swimmers' is 14 + Null('\0') = 15 Characters |
|
|
| [Q009] What will be the output of the following
program : |
int main()
{
char str[]="C For Swimmers";
printf("%d",++(sizeof(str)));
return(0);
}
|
(a)14
(b)Compile-Time Error
(c)15
(d)None of these |
| Pre- or Post-
increment/decrement operators cannot be used on the constants as
shown in the above scenario. But it can be used with variables to
increment the contents or address by 1. |
|
|
| [Q010] What will be the output of the following
program : |
int main()
{
char str[]="C For Swimmers";
printf("%d",-sizeof(str));
return(0);
}
|
(a)14
(b)Compile-Time Error
(c)-15
(d)-14 |
| After computing the size
in bytes, the binary operator - (minus) is used to change the sign
of the resultant. |
|
|
| [Q011] What will be the output of the following
program : |
int
main()
{
printf("%d",!(100==100)+1);
return(0);
}
|
(a)100
(b)0
(c)1
(d)2 |
| Negation (!) of
non-zero value always returns 0 (zero). Thus 0 + 1 = 1 |
|
|
| [Q012] What will be the output of the following
program : |
int main()
{
int x=5,y=6,z=2;
z/=y/z==3?y/z:x*y;
printf("%d",z);
return(0);
}
|
(a)Compile-Time
Error
(b)2
(c)0
(d)1 |
| Be careful while
evaluating such type of expressions. Consider the precedence during
computation which plays a major role. Here y/z yields 3 which is
equal to 3. Thus the true expression in the ternary operator y/z
yields 3. Thus z/=3 or z=2/3 yields 0 (zero) because of integer
division. Finally it prints 0 (zero) onto the screen. |
|
|
| [Q013] What will be the output of the following
program : |
int main()
{
printf("%d %d %d",5,!5,25-!25);
return(0);
}
|
(a)5 10 22
(b)5 5 25
(c)5 0 25
(d)5 1 24 |
| Negation (!) of non-zero
value always returns 0 (zero). Thus the arguments to the printf will
be 5 0 25-0. Thus it prints 5 0 25 |
|
|
| [Q014] 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);
return(0);
}
|
(a)500 100 30 40 4
(b)Run-Time Error
(c)700 200 300 10 4
(d)300 -200 300 10 4 |
| Be careful while
evaluating such type of expression. Precedence plays a major role
during computation. Here the short-hand assignment operators
precedence is from R->L. Thus it prints 300 -200 300 10 4 |
|
|
| [Q015] What will be the output of the following
program : |
int main()
{
int a=500,b=100,c=30,d=40,e=19;
if ((((a > b) ? c : d) >= e) && !((e
<= d) ? ((a / 5) == b) : (c == d)))
printf("Success");
else
printf("Failure");
return(0);
}
|
(a)Success
(b)Failure
(c)Invalid Statement(s)
(d)None of these |
| Apply the relational
& logical operators properly to arrive at the solution. Thus it
prints the message 'Failure'. |
|
|
| [Q016] What will be the output of the following
program : |
int main()
{
int a=1,b=2,c=3,d=4;
printf("%d",!a?b?!c:!d:a);
return(0);
}
|
(a)1
(b)2
(c)3
(d)4 |
| Here evaluate the ternary
operators carefully. Here !a yields 0 so it enters into the false
block and return the value of a. Thus it prints 1. |
|
|
| [Q017] What will be the output of the following
program : |
int main()
{
int i=12345,j=-13579,k=-24680;
long ix=123456789;
short sx=-2222;
unsigned ux=5555;
printf("\n%d %d %d %ld %d %u",i,j,k,ix,sx,ux);
printf("\n\n%3d %3d %3d\n%3ld %3d %3u",i,j,k,ix,sx,ux);
printf("\n\n%8d %8d %8d\n%15ld %8d %8u",i,j,k,ix,sx,ux);
printf("\n\n%-8d %-8d\n%-8d %-15ld\n%-8d
%-8u",i,j,k,ix,sx,ux);
printf("\n\n%+8d %+8d\n%+8d %+15ld\n%+8d
%8u",i,j,k,ix,sx,ux);
printf("\n\n%08d %08d\n%08d %015ld\n%08d
%08u",i,j,k,ix,sx,ux);
return(0);
}
|
| Execute & understand
the output format. |
|
|
| [Q018] What will be the output of the following
program : |
int main()
{
int i=12345,j=0xabcd9,k=077777;
printf("%d %x %o",i,j,k);
printf("\n%3d %3x %3o",i,j,k);
printf("\n%8d %8x %8o"i,j,k);
printf("\n%-8d %-8x %-8o",i,j,k);
printf("\n%+8d %+8x %+8o",i,j,k);
printf("\n%08d %#8x %#8o",i,j,k);
return(0);
}
|
| Execute & understand
the output format. |
|
|
| [Q019] What will be the output of the following
program : |
int main()
{
char c1='A', c2='B', c3='C';
printf("%c %c %c",c1,c2,c3);
printf("\n%c%c%c",c1,c2,c3);
printf("\n%3c %3c %3c",c1,c2,c3);
printf("\n%3c%3c%3c",c1,c2,c3);
printf("\nc1=%c c2=%c c3=%c",c1,c2,c3);
return(0);
}
|
| Execute & understand
the output format. |
|
|
| [Q020] What will be the output of the following
program : |
int main()
{
float a=2.5, b=0.0005, c=3000.;
printf("%f %f %f",a,b,c);
printf("\n%3f %3f %3f",a,b,c);
printf("\n%8f %8f %8f",a,b,c);
printf("\n%8.4f %8.4f %8.4f",a,b,c);
printf("\n%8.3f %8.3f %8.3f",a,b,c);
printf("\n%e %e %e",a,b,c);
printf("\n%3e %3e %3e",a,b,c);
printf("\n%12e %12e %12e",a,b,c);
printf("\n%8.2e %8.2e %8.2e",a,b,c);
printf("\n%-8f %-8f %-8f",a,b,c);
printf("\n%+8f %+8f %+8f",a,b,c);
printf("\n%08f %08f %08f",a,b,c);
printf("\n%#8f %#8f %#8f",a,b,c);
printf("\n%g %g %g",a,b,c);
printf("\n%#g %#g %#g"a,b,c);
return(0);
}
|
| Execute & understand
the output format. |
|
|
| [Q021] What will be the output of the following
program : |
int main()
{
char str[]="C For Swimmers";
printf("%s",str);
printf("\n%.5s",str);
printf("\n%8.*s",5,str);
printf("\n%-10s %.1s",str+6,str);
return(0);
}
|
| Execute &
understand the output format. |
|
|
| [Q022] What will be the output of the following
program [NOTE : 3 values entered by the user are:100 200 300] : |
int main()
{
int a=1,b=2,c=3;
scanf("%d %*d %d",&a,&b,&c);
printf("a=%d b=%d c=%d",a,b,c);
return(0);
}
|
(a)1 2 3
(b)100 200 300
(c)100 200 3
(d)100 300 3 |
| The * (asterisk) in the
scanf statement indicates an assignment suppression operator that
skips the related value and picks the next value in the input
series. |
|
|
| [Q023] What will be the output of the following
program [NOTE : THE USER INPUT IS:Dear Friends, What is the output?]
: |
int main()
{
char line[80]; // Max. length=80 Chars
scanf("%[^,]s",line);
printf("\n%s",line);
return(0);
}
|
(a)Compile-Time Error
(b)Dear Friends
(c)What is the output?
(d)None of these |
| Here the , (comma) is
used as the termination character. The scanf statement in the above
code accepts the string that contains anything other than the ,
(comma). |
|
|
| [Q024] What will be the output of the following
program [NOTE : THE USER INPUT IS :A B C] : |
int main()
{
char a,b,c;
scanf("%c%c%c",&a,&b,&c);
printf("a=%c b=%c c=%c",a,b,c);
return(0);
}
|
(a)a=A b=B c=C
(b)a=A b= c=B
(c)a=A b= c=C
(d)None of these |
| While accepting we're
expecting NO whitespaces between the three different inputs i.e.
characters but we've encountered characters in the actual input. |
|
|
| [Q025] What will be the output of the following
program [NOTE : THE USER INPUT IS:5 5.75] : |
int
main()
{
int i=1;
float f=2.25;
scanf("%d a %f",&i,&f);
printf("%d %.2f",i,f);
return(0);
}
|
(a)1 2.25 (b)5
5.75 (c)5 2.25 (d)1 5.75 |
| Here we're expecting an
integer (int) value followed by a whitespace, which is followed by a
character 'a', which in turn followed by a whitespace and a float
value. But the actual input doesn't meet our requirements hence the
only the matched arguments are taken into consideration. |
|
|
| [Q026] What will be the output of the following
program [NOTE : THE USER INPUT IS :ABC DEF GHI] : |
int
main()
{
char a,b,c;
scanf("%c %c %c",&a,&b,&c);
printf("a=%c b=%c c=%c",a,b,c);
return(0);
}
|
(a)a=ABC b=DEF c=GHI
(b)a=A b=B c=C
(c)a=A b=D c=G
(d)None of these |
| We're expecting character
inputs separated by whitespaces but the actual input contains string
of characters. |
|
|
| [Q027] What will be the output of the following
program [NOTE : THE USER INPUT IS:CMeansSea Ocean Vast] : |
int main()
{
char a[80],b[80],c[80];
scanf("%1s %5s %3s",a,b,c);
printf("%s %s %s",a,b,c);
return(0);
}
|
(a)C O V
(b)C Means Sea
(c)C Ocean Vas
(d)None of these |
| Here access format
specifier is used in the scanf statement similar to the access
format specifier usage in the printf statements. |
|
|
| [Q028] What will be the output of the following
program [NOTE : THE USER INPUT IS :123456 44 544] : |
int main()
{
int a,b,c;
scanf("%1d %2d %3d",&a,&b,&c);
printf("Sum=%d",a+b+c);
return(0);
}
|
(a)Sum=480
(b)Sum=594
(c)Sum=589
(d)None of these |
| Here access format
specifier is used in the scanf statement similar to the access
format specifier usage in the printf statements. |
|
|
| [Q029] What will be the output of the following
program : |
int
main()
{
char line[80];
scanf("%[^1234567890\n]",line);
return(0);
}
|
(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 |
| ^ indicates negation
operation. |
|
|
| [Q030] What will be the output of the following
program : |
int main()
{
char line[80];
scanf("%[^*]",line);
return(0);
}
|
(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 |
| ^ indicates negation
operation. |
|
|