Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.int *i = 55; cout << sizeof(i); What will be printed to the screen after the c

ID: 3816540 • Letter: 1

Question


1.int *i = 55;

cout << sizeof(i);

What will be printed to the screen after the code above executes?

   55
   8
   32
   4

2.Since technically all files are binary, what is the best way to describe a text file to differentiate it from a binary file?

   A text file contains binary data
   A text file only contains CPU instructions
   A text file is human readable
   A text file contains text data

3.Given:

int a[] = {1, 2, 3, 4};
ofstream fout("my.bin", ios::binary);
fout.write(reinterpret_cast<char*>(&a[1]), sizeof(int));
fout.close();

What would be written to my.bin?

   1 2 3 4
   1
   2 3 4
   3
   3 4
   1 2
   2

4.int *i = new int[10];
ifstream fin("my.bin", ios::binary);
fin.read(i, 10);

The first parameter to fin.read (underlined above) gives me a compiler error, how would I fix it?

   reinterpret_cast<char*>(i)
   reinterpret_cast<byte>(i)
   static_cast<char*>(i)
   reinterpret_cast<char>(i)

5.Binary files are opened in C++ by adding what special flag to .open()?

   ios::b
   ios::bfile
   ios::bin
   ios::binary

6.int arr[] = {1, 2, 3};

cout << sizeof(arr);

What would be printed to the screen?

   16
   12
   4
   3

7.Using binary files, if I wanted to read in an entire structure all at once, what member function of ifstream would I use?

   .write()
   >>
   .read()
   <<

Explanation / Answer

1.int *i = 55;

cout << sizeof(i);

What will be printed to the screen after the code above executes?

Answer: 4

Program:

#include <iostream>

using namespace std;

int main() {
   int i = 55;

cout << sizeof(i);
}

Output: 4

5.Binary files are opened in C++ by adding what special flag to .open()?

Answer: ios::binary

Explanation:

int main()
{
ifstream infile;
infile.open("hello.dat", ios::binary | ios::in);
// rest of program

}

6.int arr[] = {1, 2, 3};

cout << sizeof(arr);

What would be printed to the screen?

Answer: 12

Program:

#include <iostream>

using namespace std;

int main() {
int arr[] = {1, 2, 3};
cout << sizeof(arr);
}

Output: 12

7.Using binary files, if I wanted to read in an entire structure all at once, what member function of ifstream would I use?

Answer:  .read()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote