Questions tagged [static-array]
56 questions
                    
                    75
                    
            votes
                
                14 answers
            
        Programmatically create static arrays at compile time in C++
One can define a static array at compile time as follows:
const std::size_t size = 5;    
unsigned int list[size] = { 1, 2, 3, 4, 5 };
Question 1 - Is it possible by using various kinds of metaprogramming techniques to assign these values…
         
    
    
        Hippicoder
        
- 1,565
- 3
- 17
- 21
                    58
                    
            votes
                
                3 answers
            
        Difference between char and char[1]
In C++ what is the difference (if any) between using char and char[1].
examples:
struct SomeStruct
{
   char x;
   char y[1];
};
Do the same reasons follow for unsigned char?
        Matthieu N.
                    10
                    
            votes
                
                3 answers
            
        how to extract the name attribute from string array?
Hi I build a quiz application.
I have the following (values/)question.xml
- A
- B
- C
- 
        
            
            
                
                    
    
    
          
  
 
    
    
        flangofas
        
- 332
- 1
- 5
- 15
                    10
                    
            votes
                
                5 answers
            
        How to initialise static arrays in D without a GC allocation?
In D, all array literals are dynamic arrays, and are therefore allocated by the GC.
Even in this simple example:
int[3] a = [10, 20, 30];
The array is heap-allocated and then copied into a.
How are you supposed to initialise a static array without…
         
    
    
        Peter Alexander
        
- 53,344
- 14
- 119
- 168
                    10
                    
            votes
                
                4 answers
            
        static arrays defined with unspecified size, empty brackets?
For the C++ code fragment below:
class Foo {
    int a[]; // no error
};
int a[];     // error: storage size of 'a' isn't known
void bar() {
    int a[]; // error: storage size of 'a' isn't known
}
why isn't the member variable causing an error…
         
    
    
        Ahmed Abdelkader
        
- 1,695
- 1
- 13
- 12
                    9
                    
            votes
                
                1 answer
            
        Objective-C static inline NSString array
Hi :) I am trying to create a static C-Array of NSStrings.
This is what I tried:
static NSString** polygonNames = {@"Radical Isotope", @"Point", @"Line", @"Triangle", @"Square", @"Pentagon", @"Hextagon", @"Heptagon", @"Octagon", @"Nonagon",…
         
    
    
        Georges Oates Larsen
        
- 6,812
- 12
- 51
- 67
                    6
                    
            votes
                
                5 answers
            
        Can we create static array with a size that is an execute-time constant?
We all know the basic rules for static array:
int size = 20;
char myArray[size];
is not legal.
And.
const int size = 20;
char myArray[size];
is OK.
But, what about this.
int f(const int size)
{
    char myArr[size];
}
void main()
{
   f(2);
  …
         
    
    
        jslap
        
- 711
- 1
- 6
- 21
                    6
                    
            votes
                
                3 answers
            
        Count the number of elements in an array in C
How can I obtain the number of elements present in an integer array in C after the array is passed to a function?  The following code doesn't work.
size=sizeof(array)/sizeof(array[0]);
        user2266758
                    6
                    
            votes
                
                2 answers
            
        static array class variable "multiple definition" C++
I'm writing some code where I need to have a class variable that's a static int array.  I understand that I can do this with something like this in the header file, A.h:
#ifndef A_H_
#define A_H_
class A
{
public:
  static const int a[];
};
const…
         
    
    
        rainbowgoblin
        
- 1,221
- 12
- 28
                    5
                    
            votes
                
                2 answers
            
        "dynamic array of static arrays"
How do you specify a dynamic array of static arrays in C?
I want to make a struct holding two dynamic arrays of static arrays.
struct indexed_face_set {
    double * [3] vertices;
    int * [3] faces;
};
This should hold a dynamic list of vertices,…
         
    
    
        user1858467
        
- 71
- 1
- 5
                    4
                    
            votes
                
                2 answers
            
        what is the point of having static arrays
I don't have a background in C or C++, so static arrays puzzle me a little. What are they for? Why are they allocated on the stack? 
I imagine there's a performance benefit. Stack allocation is faster and there's no need for garbage collection. But…
         
    
    
        fwend
        
- 1,813
- 2
- 15
- 17
                    4
                    
            votes
                
                5 answers
            
        How does one declare a static array of custom data type with hard-coded values?
Goal:
I want to implement a hard-coded lookup table for data that doesn't change often, but when it does change I want to be able to quickly update the program and rebuild.
Plan:
My plan was to define a custom data type like so...
private class…
         
    
    
        Someone Somewhere
        
- 23,475
- 11
- 118
- 166
                    3
                    
            votes
                
                2 answers
            
        how to initialize static array within struct
I have this struct:
typedef struct {
    int start;
    int end;
    char board[10][10]; 
} move;
when I try initializing it this way:
char new_board[10][10]
move struct new_move = {0, 0, new_board}
I get this error:
warning C4047: 'initializing'…
         
    
    
        ishefi
        
- 480
- 4
- 12
                    3
                    
            votes
                
                4 answers
            
        How to define a static array without a contant size in a constructor of a class? (C++)
I have a class defined as:
class Obj {
public:
    int width, height;
    Obj(int w, int h);
}
and I need it to contain a static array like so:
int presc[width][height];
however, I cannot define within the class, so it it possible to create a…
        user98188
                    3
                    
            votes
                
                3 answers
            
        Strange behavior adding this object to this static array
At the moment I test with this piece of code:
type = $type;
       …
         
    
    
        Ron van der Heijden
        
- 14,803
- 7
- 58
- 82