C& CPP Tutorials
About C
Program Structure
Running C Program
Variables, constants
Operators
Control Structure
Array
Function
Pointers
Preprocessor
Structure
File
Bitwise Operators
Recursion
 Data Structures
Introduction
Stacks
Queues
Linked List
Sorting 
Searching
 Test Your Skill
Fundamentals
Input and Output
Branching and Looping
Function
Pointers I
Pointers II
Structure and Union
Sample Problems I
Sample Problems II
 Help and Support
C Forum
Source code
C Yahoo Group
C Compilers
 

C Fundamentals

Data Types, Constants & Variables, Playing with scanf function, Operators & Expressions

[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

 [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) ' '

[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/-"

[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

[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

[Q006] What will be the output of the following program :

 int main()
   {
     char str[]="C For Swimmers";
     printf("%d",sizeof str);
     return(0);
   }

 (a)2
 (b)Compile-Time Error
 (c)4
 (d)None of these

[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

[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

[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

 [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

[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

[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

[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

[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

[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

[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

 [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);
 }
[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);
 }
 [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);
 }

[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);
 }

[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);
 }

 [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
[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
[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
[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)Printing...97
 (b)97
 (c)Compile-Time Error
 (d)a
 
[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
[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
 [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
 [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
[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

Solutions for the above queries.

Back Next
 

Google