TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ken H
NA
646
360.6k
Structure of assigning values to an array member in C++
Dec 29 2014 12:56 AM
Hello friend,
My code is as follows(In bold-part question):
#include "stdafx.h"
#include <iostream>
using namespace std;;
#define MAX_ARR_SIZE 10
typedef int ElementType;
typedef struct
{
ElementType arr[MAX_ARR_SIZE];
int length;
}MyStr;
void outputE(MyStr *ms){
int i;
for (i = 0; i < ms->length; i++) cout << ms->arr[i] << ",";
cout << ms->arr[i] << endl;
}
int _tmain(int argc, _TCHAR* argv[]){
MyStr ms;
ms.length = MAX_ARR_SIZE;
//
try a one-time assignment. but a compiler error has occurred(In addition to each assignment, but are there other ways?).
ms.arr[MAX_ARR_SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
outputE(&ms);
system("pause");
return 0;
}
Thanks.
Reply
Answers (
2
)
Vc++ related question
What are the ways to pause console page after run in C++?