C programming Cast Type Aptitude Questions and Answers

This section contains Aptitude Questions and Answers on Cast Typing, Basically in C programming language there are two types of cast type - Implicit and Explicit.

List of Cast Type Aptitude Questions and Answers

1) What will be the output of following program ?
#include <stdio.h>
 
int main()
{
    int x=65;
    const unsigned char c=(int)x;
     
    printf("%c\n",c);
 
    return 0;
}
  1. Error
  2. 65
  3. A
  4. Null

2) What will be the output of following program ?
#include <stdio.h>
 
int main()
{
    int x=2.3;
    const char c1=(float)x;
    const char c2=(int)x;
     
    printf("%d,%d\n",c1,c2);
 
    return 0;
}
  1. Error
  2. 2.3,2
  3. 2.300000,2
  4. 2,2


3) What will be the output of following program ?
#include <stdio.h>
 
int main()
{
    char *text="Hi Babs.";
     
    char x=(char)(text[3]);
     
    printf("%c\n",x);
     
    return 0;
}
  1. Garbage
  2. B
  3. Error
  4. Null

4) What will be the output of following program (on 32 bit compiler)?
#include <stdio.h>
 
int main()
{
    int x=65;
    const unsigned char c=(int)x;
     
    printf("%c\n",c);
 
    return 0;
}
  1. 65.00
  2. 65
  3. A
  4. Error





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.