Linked Questions

67 votes
6 answers
237k views

Zero an array in C code [duplicate]

Possible Duplicates: How to initialize an array to something in C without a loop? How to initialize an array in C How can I zero a known size of an array without using a for or any other loop ? ...
Batman's user avatar
  • 1,344
28 votes
4 answers
290k views

How to set all elements of an array to zero or any same value? [duplicate]

I'm beginner in C and I really need an efficient method to set all elements of an array equal zero or any same value. My array is too long, so I don't want to do it with for loop.
user3610709's user avatar
17 votes
5 answers
4k views

c++ array initialization [duplicate]

Possible Duplicate: array initialization, is referencing a previous element ok? I wonder if its safe to do such initialization in c/c++ standard: int a = 5; int tab[] = { a , tab[0] + 1 , tab[1] }; ...
qba's user avatar
  • 1,311
7 votes
6 answers
20k views

How to initialize an array with only -1 values [duplicate]

Possible Duplicate: How to initialize an array in C initializing an array of ints I wonder over the fastest/simplest way to initialize an int array to only contain -1 values. The array I need is ...
patriques's user avatar
  • 5,241
9 votes
4 answers
8k views

Initialize an array of structs in C or C99 to all the same values [duplicate]

Lets assume the following in C or C99: typedef struct { int x; double y; } MY_S; MY_S a[666] = {333, 666.6}; Does this initialize the first object of the array only? If yes, is there a way to ...
Silicomancer's user avatar
  • 9,384
1 vote
2 answers
6k views

How to initialize large size of array to 0 in C [duplicate]

I am trying to initialize all columns and rows of array of large size to 0, without using pointers in C. But sometimes it is getting a crash and sometimes it shows an error message about 'not enough ...
user2894607's user avatar
4 votes
2 answers
555 views

Why {0} assignation works but not {5} for an array [duplicate]

I tried the following code: int a[4] = {0}; int b[4] = {5}; int c[4]; printf("%d %d %d %d %d %d\n", a[0], a[3] , b[0], b[3], c[0], c[3]); And got the following result: 0 0 5 0 random random While I ...
Stoogy's user avatar
  • 1,351
1 vote
2 answers
1k views

How to create multiple global variables using a for loop outside of a function? [duplicate]

I have a list and I want to create a global counter for each item in the list, with the initial value set to 1. I thought I would do this with a for loop (my actual list is a lot bigger than the ...
david_10001's user avatar
4 votes
3 answers
359 views

Correct and simplest syntactical way to initialise an array to 0 [duplicate]

I am trying to find out the correct way to initialise an array to all zeros (i.e. as if you have done a memset on the array). I have found the following methods from various areas in stack overflow (...
code_fodder's user avatar
  • 16.6k
0 votes
3 answers
971 views

Why a new string I create in C has ╠ instead of blanks? [duplicate]

When I intialize a string: char pol[100]; and printf it, I get this weird ╠ sign 100 times. My question is how to intialize a string, print it and get only blanks? Thanks!
Idan's user avatar
  • 227
-2 votes
1 answer
2k views

Simplest way to fill an array in a struct after declaration in one operation [duplicate]

I have a structure which contain a long array. I know that possible initialize an array when defined: uint8_t array[] = {0x10, 0x11, 0xa2, 0xa5}; My question is: is it possible to set all elements of ...
titapo's user avatar
  • 135
-2 votes
1 answer
827 views

an array of people using structs in c? [duplicate]

I need to create an array of persons whilst using a struct something like this :- typedef struct Person { int age; //needs to be randomly generated int height; //needs to be ...
user3385485's user avatar
1 vote
1 answer
415 views

Initializing Variables from an Array of names and values [duplicate]

I am programming in C and have initialized 2 arrays as shown below: char names[3][10] = {"foo","ba", "foofoo"}; int values[3] = {1,2,3}; I would like to initialize these in the form: int foo = 1; ...
user3457573's user avatar
-2 votes
3 answers
205 views

Initialization of Chars [duplicate]

I have been wondering, why can I not write my code like so: char myChar[50]; myChar = "This is a really cool char!"; Or at least like this: char myChar[50]; myChar[0] = "This is a really cool char!";...
AbsoluteZ3r0's user avatar
1 vote
2 answers
217 views

How to initialize a large private array in a class using constructor(just a constructor) in c++? [duplicate]

Suppose we have a class like the following one: class myprogram { public: myprogram (); private: double aa,bb,cc;}; myprogram::myprogram():aa(0.0),bb(0.0),cc(0.0){} As you can see we can initialize ...
Seyyed Kazem Razavi's user avatar

15 30 50 per page
1
2 3 4 5
10