Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
1
vote
Accepted
Help me find the bug in this array code
you have your second for loop nested inside the first one which means that the second for loop is not executed after votecounter[1] to votecounter[4] are initialized to 0, but rather it's executed onc …
18
votes
Accepted
Array Initializer Must Be an Initializer List or String Literal
First, when declaring a char array, you've to specify its size within the brackets like:
char arr[10];
except when you're initializing it with a string literal. … Edit: the error
array initializer must be an initializer list or string literal
means that when you declare an array, you have to initialize it using one of the following methods:
char arr[6] …
2
votes
Accepted
How to Form a Single Integer from the Elements of an int Array?
store the result in a new variable, you may multiply x by 10 first, then add them and store the result in a new int variable
int sum = (x * 10) + y;
printf("%d\n", sum);
Update: in case you have an array …
4
votes
Accepted
Comparing arrays in C
Have a look at memcmp()!
Also, you can define your own function
bool compare(datatype array1[], datatype array2[], size_t size1, size_t size2)
{
// check whether they're both of the same size
…
6
votes
pset7: understanding php arrays
Meanwhile, if you tried to dump() the variable named $cash, you'd find that it's a multi-dimensional array. …
1
vote
Accepted
How to create an array/subarray by extracting a part of another array?
You could do something like
if (array[0] == val0 && array[1] == val1 && array[2] == val2 && array[3] == val3)
{
// do something
}
However, if you need to extract the first n elements of an int array … [i];
}
}
The previous function takes 3 arguments, the array from which you wanna extract the first n elements (i.e., srcArray), the array to which you wanna extract these elements (i.e., subArray …
0
votes
array of strings
You need to determine the maximum length of any string that your program takes as input then to create your array like that
char T[n][max];
where n is the total number of strings and max is the maximum …
0
votes
Accepted
How are associative arrays like hash-tables?
A hash-table basically maps keys to values (it basically consists of these two parts — the keys part and the values part). If you used a hash-table in pset6, you'd probably know that you had to implem …
0
votes
Accepted
Can I create and initialize arrays of other types the same way I can create and initialize c...
Array names decay to pointers (i.e., if you used the name of an array by itself, then you're using a pointer to the whole array which happens to be also a pointer to the first element in the array). … So str here is mainly a pointer to the whole array, but it also could be a pointer to the first element in the array (i.e., the char 'f' in this case). …
1
vote
unable to use a 2d array via function
A function that takes a 2D-array as an argument may have the following prototype
void foo(int arr[][<cols>]);
where <cols> is the number of columns in the array to be passed. … The following piece of code passes a 2D-array to foo (declared above)
int bar[3][3];
foo(bar);
Notice that I'm not passing &bar because that would be a pointer to my 2D-array not my 2D-array itself. …
1
vote
Accepted
Try to sort strings with merge sort
First, this is not a 2D array of strings. It's a 2D array of chars and 1D array of strings. …
4
votes
about strings and arrays
allocates a chunk of memory, reads the string that the user enters character by character, stores the current character at the appropriate location and, if at some point there's not enough space left in the array … , it reallocates a new array with ~double the size of the older one, copies the contents of the older array into the newer array, frees the older array and the process repeats. …
7
votes
Accepted
not fully understanding dynamically sized array in server.c pest
of course needle and haystack both are pointers and thus they both store addresses which are essentially numbers so we can perform arithmetic operations on them.
needle - haystack + 2 + 1
subtract …
2
votes
Accepted
declaring char array vs malloc
when you declare an array of a certain size, depending on where you declare your array, the memory for it may get allocated on the stack (e.g., if it's declared as a local variable — inside of a function … memory allocated on the stack gets freed automatically as your array (or more generally, local variable) gets out of scope. so you don't have to worry about manually freeing your memory. …
2
votes
Accepted
How Does sizeof() Work?
The size of a 5-int array is 20 bytes (5 ints * 4 bytes each). The sizeof() operator is used to calculate the size of any datatype in bytes. For more information, you may read this wikipedia article! …