Question

Write a program with several variables of various data types such as int, long long int,...

Write a program with several variables of various data types such as int, long long int, float, double, char, and check their sizes in terms of bytes.

Make sure you do screen output of the bytes.

For C++ please

Homework Answers

Answer #1
#include <iostream>
using namespace std;

int main()
{
  int integerType;
  long long int longlongType;
  float floatType;
  double doubleType;
  char charType;

  // int
  cout << "Size of int is: " << sizeof(integerType) << " bytes\n";
  // long long int
  cout << "Size of long long int is: " << sizeof(longlongType) << " bytes\n";
  // float
  cout << "Size of float is: " << sizeof(floatType) << " bytes\n";
  // double
  cout << "Size of double is: " << sizeof(doubleType) << " bytes\n";
  // char
  cout << "Size of char is: " << sizeof(charType) << " bytes\n";


  return 0;
}

OUTPUT:

Explanation: We can use sizeof() function to calculate the size of different data types in C++.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a simple program that displays 4 python primitive data types sizes in bytes run the...
write a simple program that displays 4 python primitive data types sizes in bytes run the program on a command prompt CMD. attach a photo of the source file in the text editior and the excutable on CMD ex; the size of int in bytes is ... the size of floot in bytes is ... the size of string in bytes is ... the size of char in bytes is ....
The data types of: 47+6.5, 2*6e-2L, +'0', and sizeof(38.2) are: (Note 2.10) A. float, long, char,...
The data types of: 47+6.5, 2*6e-2L, +'0', and sizeof(38.2) are: (Note 2.10) A. float, long, char, unsigned int B. int, long, char, size_t C. double, long double, int or unsigned, size_t D. int, long double, int, double E. implementation dependent
1. The data type that size_t represents is implementation dependent. Which are the only data types...
1. The data type that size_t represents is implementation dependent. Which are the only data types permitted? (Note 2.12) A. signed char, short, int, long, long long B. unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long C. float, double, long double D. char, unsigned short, unsigned int, unsigned long, unsigned long long E. any arithmetic data type
Goals: Write a program that uses binary files. Write a program that stores records to a...
Goals: Write a program that uses binary files. Write a program that stores records to a binary file. C++ Requirements: Write a program that includes a structure named Part that contains the following fields: name - a character array of 20 elements that stores the name of the part. qty - an integer that stores the number of parts in stock. price - a double that stores the price of the part. Create three Part variables in main, and fill...
Research and Discuss variables and data types. 1. What are the various data types you can...
Research and Discuss variables and data types. 1. What are the various data types you can use in C#, Explain memory sizes of these data types? 2. Discuss string variables. What does a string variable provide? Provide details. 3. Provide examples how you would create a values like "Sarah", 2, 3.50, and store into memory. For example, DataType VariableName = "Sarah".
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Program: 6: Function overloading AIM: To write a C++ program to illustrate the concept of function...
Program: 6: Function overloading AIM: To write a C++ program to illustrate the concept of function overloading. PSEUDOCODE: Declare necessary variables. Create a class with add(int,int) ,add(float,float) as member functions and necessary variable. add(int,int) is used to add two integer values. add(float,float) is used to add two float values. Using object call the required function with corresponding input. Display the output.
Write a C program that reads in a float constant (use %f in scanf) and displays...
Write a C program that reads in a float constant (use %f in scanf) and displays its internal representation in hex. Use your program to check your answers to problem 1. Hint: a union is like a struct except that the fields overlap. Hint: the conversion code for hex is %x. union X { int a; float b; }; int main() { union X test; ... ; test.a and test.b refer to same word in memory but have ; different...
1. Type in the following program. Compile and run. #include <iostream> using namespace std; int main()...
1. Type in the following program. Compile and run. #include <iostream> using namespace std; int main() { ​cout << "Hello, world." << endl; } Open a Word Document and copy and paste the program and the output. 2. Create a new program: #include <iostream> using namespace std; int main() { ​float num1; ​float num2 ​float avg; ​cout << "Enter two numbers" << endl; ​cin >> num1 >> num2; ​avg = num1 + num2/2; ​cout << "The average is " <<...
Write a C++ program to do the following: Declare and assign values to int variables x,...
Write a C++ program to do the following: Declare and assign values to int variables x, y Declare an int variable z; and store the sum of x and y in it Declare a pointer called pz and point it in the heap direction (using new) Store the z value in the heap location using the pz pointer Print the content of the pz pointer Print the pointer (the address)