--Originally published at Programming
Well in this quiz ask for various activities, so its good to practice.
Important things:
- Note that you will also need to include <stdio.h>
- printf will also complain that you are not passing an int to the %d so perhaps you want to cast the sizeof value to an int like this:
int(sizeof(c)*8)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For the first exercise:
Type in the following program and run it:
#include
main()
{ /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */
char c;
short s;
int i;
unsigned int ui;
unsigned long int ul;
float f;
double d;
long double ld;
cout << endl
<< "The storage space for each variable type is:"
<< endl;
cout << endl << "char: \t\t\t%d bits",sizeof(c)*8; // \t means tab
cout << endl << "short: \t\t\t%d bits",sizeof(s)*8;
cout << endl << "int: \t\t\t%d bits",sizeof(i)*8;
cout << endl << "unsigned int: \t\t%d bits",sizeof(ui)*8;
cout << endl << "unsigned long int: \t%d bits",sizeof(ul)*8;
cout << endl << "float: \t\t\t%d bits",sizeof(f)*8;
cout << endl << "double: \t\t%d bits",sizeof(d)*8;
cout << endl << "long double: \t\t%d bits",sizeof(ld)*8;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For the second exercise:
Write a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:
Input a single character, followed by : h
Input an integer, followed by : 4872
Input a float, followed by : 182.937
The character h when cast to an int gives value ?????
The character h when cast to a float gives value ?????
The integer 4872 when cast to a char gives value ?
The integer 4872 when cast to a float gives value ?????
The float 182.937 when cast to a char gives value ?
The float 182.937 when cast to an
Continue reading "Quiz #6" →