Saturday, 12 March 2016

Declare a variable of the type defined in Question 8 and initialize it.

Leave a Comment

Question:

9. Declare a variable of the type defined in Question 8 and initialize it.

Answer:

#include<iostream>
using namespace std;
struct fish {
       char kind[20];
       int weight;
       float length;
};

void main() {
       fish petes =
       {
              "trout",
              12,
              26.25
       };
       cout << petes.kind << endl
              << petes.length << endl
              << petes.weight << endl;
}

Source:

C++ Primer Plus Sixth Edition Chapter Review

If You Enjoyed This, Take 5 Seconds To Share It