like this ?

Copystruct  {
    const char *s;
    double f;
} obj[] = {
    { .s = "ejf09j290fj390j2f09", .f = 0 },
    { .s = "dj320992209920209dj", .f = 0 }
};
Answer from BLUEPIXY on Stack Overflow
Top answer
1 of 2
4

like this ?

Copystruct  {
    const char *s;
    double f;
} obj[] = {
    { .s = "ejf09j290fj390j2f09", .f = 0 },
    { .s = "dj320992209920209dj", .f = 0 }
};
2 of 2
1

Where JavaScript has dynamic "properties", C has static "tags". A struct type is defined as a sequence of tags, which each have a type.

For the type inside your example array

CopyarrayOfObjectsInsideJavascript = [
    { s:"ejf09j290fj390j2f09", f=0 },
    { s:"dj320992209920209dj", f=0 }
]

your last solution started off almost correctly:

Copystruct element {
    char s[256];
    int f;
};

You have two options for the type of s:

  • If you want to store the string inside the object, you use some array type, such as char s[256]. 256 is the length of the array, so when you use zero-terminated strings, the maximum allowed string length is 255 (which is 256, minus one for the '\0' character).
  • If you want to store the string outside the object, you use some pointer type. Since you want to use string literals, you should declare the tag as const char *s. Changing a string literal causes undefined behaviour, so it's best to prevent yourself from doing so.

For this answer, I'll use the first option in the examples.


If you want to define one struct, you could now write something like

Copystruct element {
    char s[256];
    int f;
} one_object = {
    .s = "ejf09j290fj390j2f09",
    .f = 0,
};

or

Copystruct element {
    char s[256];
    int f;
};

/* ... later, in a scope where `struct element` is visible ... */

struct element one_object = {
    .s = "ejf09j290fj390j2f09",
    .f = 0,
};

or, with a typedef,

Copytypedef struct {
    char s[256];
    int f;
} your_element_type;

/* ... later, in a scope where `your_element_type` is visible ... */

your_element_type one_object = {
    .s = "ejf09j290fj390j2f09",
    .f = 0,
};

Note that this doesn't necessarily work with older compilers that don't support the C99 standard. In the older days, you'd have to initialise fields in order:

Copyyour_element_type one_object = { "ejf09j290fj390j2f09", 0 };

Also note that, if you're never going to refer to the type name struct element again, you don't have to name it:

Copystruct {
    char s[256];
    int f;
} one_object = {
    .s = "ejf09j290fj390j2f09",
    .f = 0,
};

Arrays are initialised similarly (you've actually already initialised an array, namely s, with a string):

Copystruct element {
    char s[256];
    int f;
} so_many_objects[] = {
    { .s = "ejf09j290fj390j2f09", .f = 0 },
    { .s = "dj320992209920209dj", .f = 0 },
};

or

Copystruct element {
    char s[256];
    int f;
};

/* ... later, in a scope where `struct element` is visible ... */

struct element so_many_objects[] = {
    { .s = "ejf09j290fj390j2f09", .f = 0 },
    { .s = "dj320992209920209dj", .f = 0 },
};

or, with a typedef again,

Copytypedef struct {
    char s[256];
    int f;
} your_element_type;

/* ... later, in a scope where `your_element_type` is visible ... */

your_element_type so_many_objects[] = {
    { .s = "ejf09j290fj390j2f09", .f = 0 },
    { .s = "dj320992209920209dj", .f = 0 },
};

By the way, note that we are using an incomplete type for so_many_objects; this is only possible because the compiler can see how big the array should be. In these examples, the compiler would treat your code as if you'd have written struct element so_many_objects[2]. If you think you'll have to extend the array with more objects, you'd better specify how many elements the array has (at maximum), or learn about dynamic allocation.

🌐
GeeksforGeeks
geeksforgeeks.org › c++ › array-of-objects-in-c-with-examples
Array of Objects in C++ with Examples - GeeksforGeeks
July 23, 2025 - To add to it, an array in C/C++ can store derived data types such as structures, pointers, etc. Given below is the picture representation of an array. Example: Let's consider an example of taking random integers from the user. ... When a class is defined, only the specification for the object is defined; no memory or storage is allocated.
Discussions

How to Create an array of objects? - C++ Forum
In array all objects are constructed in time of array declaration. That means you either should provide 20 initializers for your array (see exampe with 3 in my post earlier) or provide a default constructor and assign other values later. You might consider using vector instead. More on cplusplus.com
🌐 cplusplus.com
Array of objects questions. - C++ Forum
Array of objects questions. ... I am very confused about array of objects coding. I have looked around a bit, and nothing of what I found was helpful in having me actually understand it (cause most of it was just all code and no words). So I don't know how to work an array of objects for data ... More on cplusplus.com
🌐 cplusplus.com
How to create an array of objects from classes?
You're pretty much there. zombie[] zomb = new zombie[88] will create the array, you would just need to instantiate each index of the array. More on reddit.com
🌐 r/csharp
44
15
August 31, 2022
array of objects
For my model railroad I wrote a processing sketch which has several objects in an array list. When the program is running I can add and remove objects and toggle states of things etc etc. Now I am writing the arduino side of the story. At the moment I am writing my Switch class. More on forum.arduino.cc
🌐 forum.arduino.cc
0
0
January 15, 2019
🌐
Reddit
reddit.com › r/learnprogramming › how to create an array of objects that holds objects of two classes derived from a single class? c++
r/learnprogramming on Reddit: How to create an array of objects that holds objects of two classes derived from a single class? C++
May 7, 2022 -

So there's this base class and two other classes have been derived from it. How does one create an array that holds objects of both derived classes?

EDIT: I did managed to achieve this by creating an array of pointers of type base i.e Base * arr[10]; and stored the addresses of the objects of the derived classes inside it.

🌐
Tutorjoes
tutorjoes.in › c_programming_tutorial › array_of_objects_in_c
Creating an Array of Structures in C
You can access the elements of the array using the array · index, and access the members of the structure using the ... //Array of Structure Objects #include<stdio.h> struct student { char *name; int age; float per; }; int main() { struct student o[2]; o[0].name="Ram Kumar"; o[0].age=25; o[0].per=65.25; o[1].name="Sam Kumar"; o[1].age=12; o[1].per=80; printf("\n------------------------------"); printf("\nName : %s",o[0].name); printf("\nAge : %d",o[0].age); printf("\nPercent : %f",o[0].per); printf("\n------------------------------"); printf("\nName : %s",o[1].name); printf("\nAge : %d",o[1].age); printf("\nPercent : %f",o[1].per); printf("\n------------------------------\n\n"); return 0; } To download raw file Click Here
🌐
Cplusplus
cplusplus.com › forum › beginner › 171111
How to Create an array of objects? - C++ Forum
In array all objects are constructed in time of array declaration. That means you either should provide 20 initializers for your array (see exampe with 3 in my post earlier) or provide a default constructor and assign other values later. You might consider using vector instead.
🌐
Virginia Tech
people.cs.vt.edu › kafura › cs2704 › arrays.html
Declaring Arrays of Objects
July 23, 1996 - The windows are the same shape and are aligned horizontally with the vertical edges of adjacent windows touching. from left to right, each window has one of the numbers from 1 to 10 written in it. Each "wave" beings with the leftmost window moving up vertically and then back to its original position. This same action is repeated for each window from left to right. Repeat this for a few waves. In this version declare the array so that the constructor with no arguments is used. Modify the "Frame Wave" program so that each object in the array is constructed by giving values for each constructor argument.
🌐
codezone online blog
codezone.blog › home › programing › array of objects in c++: a beginner’s guide you’ll actually understand
Array of Objects in C++: A Beginner's Guide You'll Actually Understand - codezone online blog
November 30, 2025 - Essentially, an array of objects in C++ functions just like a regular array but contains class objects instead of primitive data types. We declare these arrays by defining the variable type, specifying the array name with square brackets, and ...
Find elsewhere
🌐
Cplusplus
cplusplus.com › forum › beginner › 42815
Array of objects questions. - C++ Forum
Anything anyone could tell me that can help me understand this would be greatly appreciated. ... An array is simply a list of objects stored consecutively. Each object can be accessed by its position in the array. char arr[] = { 'a', 'b', 'c', 'd' }; This is an array of the first four letters ...
🌐
Techotopia
techotopia.com › index.php › Working_with_Objective-C_Array_Objects
Working with Objective-C Array Objects - Techotopia
An array is an object that contains collections of other objects. Array objects in Objective-C are handled using the Foundation Framework NSArray class. The NSArray class contains a number of methods specifically designed to ease the creation and manipulation of arrays within Objective-C programs.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › c-array-of-structure
Array of Structures in C - GeeksforGeeks
So for that, we need to define 50 variables of struct Employee type and store the data within that. However, declaring and handling the 50 variables is not an easy task. Let's imagine a bigger scenario, like 1000 employees. So, if we declare the variable this way, it's not possible to handle this. struct Employee emp1, emp2, emp3, .. . ... . .. ... emp1000; For that, we can define an array whose data type will be struct Employee soo that will be easily manageable.
Published   October 21, 2025
🌐
Reddit
reddit.com › r/csharp › how to create an array of objects from classes?
r/csharp on Reddit: How to create an array of objects from classes?
August 31, 2022 -

Like, instead of making : zombie zom1 = new zombie() zombie zom2 = new zombie() zombie zom3 = new zombie() And so on, I want to instead make something like: zombie[] zomb = new zombie[88] And randomly choose a zombie from the 88 to do an action, like: zomb[R].shriek() Where R is a random number

🌐
Arduino Forum
forum.arduino.cc › projects › programming
array of objects - Programming - Arduino Forum
January 15, 2019 - For my model railroad I wrote a processing sketch which has several objects in an array list. When the program is running I can add and remove objects and toggle states of things etc etc. Now I am writing the arduino si…
🌐
Unstop
unstop.com › home › blog › array of objects in c++ | declare & initialise (+ examples)
Array Of Objects In C++ | Declare & Initialise (+ Examples)
June 18, 2025 - An array of objects in C++ lets us store multiple objects of a class. It facilitates access to and data manipulation. Learn to declare them & more, with examples!
🌐
Scribd
scribd.com › document › 805044759 › Array-of-Objects-in-C-Unit-1-Docx
Array of Objects in C - (Unit-1) | PDF
A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings.
🌐
Reddit
reddit.com › r/c_programming › can someone explain how does array of structures work?
r/C_Programming on Reddit: Can someone explain how does array of structures work?
January 15, 2023 -

Good day,

So I created a structure Position with two int members.

struct Position {
    int x;
    int y;
};

typedef struct Position Position;

int main() {
    Position *current = (Position*)malloc(sizeof(Position));
    ...
}

If I want to create an array of it, should I just multiply it to how many elements I want to use?Does pointer arithmetic will move me to the next element struct every time I add 1 to the pointer?Why when I try to reallocate it by multiplying to higher number, it returns invalid pointer even though I just passed the pointer coming from malloc(). Thanks for answering and have a nice day.

🌐
Scribd
scribd.com › document › 891438492 › An-Array-of-Objects-in-C
An Array of Objects in C | PDF | Object Oriented Programming | C++
An Array of Objects in C - Free download as Word Doc (.doc / .docx), PDF File (.pdf), Text File (.txt) or read online for free. The document explains the concept of arrays of objects in C++, detailing their declaration, initialization, and various methods for manipulation.
🌐
Unreal Engine
forums.unrealengine.com › development › programming & scripting › c++
How to create an array of sub objects? - C++ - Epic Developer Community Forums
May 26, 2017 - As in topic, I know how to create a sub object for an object: UPROPERTY( EditAnywhere, Instanced ) MyObject* m_obj; and in constructor: m_obj = ObjectInitializer.CreateDefaultSubobject< MyObject >( this, TEXT( “OBJ” …
🌐
Sololearn
sololearn.com › en › Discuss › 1671932 › how-to-make-an-array-that-has-objects-made-from-different-classes-in-c
How to make an array that has objects made from different classes in C++ | Sololearn: Learn to code for FREE!
Sure, you can give Base a virtual function and have Derived implement that but you still wouldn't know that it is an object from Derived, this is where identifiers come in. What if we used an enum that tells us the type? class Base { public: enum class Type{ None, Type1, Type2 } Type GetType() const noexcept { return m_Type; } virtual ~Base(){} protected: Type m_Type = Type::None; }; class Derived : public Base { public: // Assign m_Type with a unique enum Derived(){ m_Type = Type::Type1; } void DoSomething(){ ...
🌐
TutorialsPoint
tutorialspoint.com › objective_c › objective_c_arrays.htm
Objective-C Arrays
Objective-C programming language provides a data structure called the array, which can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an