Linked Questions

1813 votes
6 answers
205k views

I bumped into this strange macro code in /usr/include/linux/kernel.h: /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the expression ...
chmurli's user avatar
  • 15.2k
81 votes
12 answers
22k views

The standard array-size macro that is often taught is #define ARRAYSIZE(arr) (sizeof(arr) / sizeof(arr[0])) or some equivalent formation. However, this kind of thing silently succeeds when a pointer ...
nneonneo's user avatar
  • 181k
51 votes
9 answers
99k views

char* names[]={"A", "B", "C"}; Is there a way to find the number of strings in the array? For example, in this case it should output: 3.
user1128265's user avatar
  • 3,059
28 votes
4 answers
125k views

How to find the size of an integer array in C. Any method available without traversing the whole array once, to find out the size of the array.
AGeek's user avatar
  • 5,265
19 votes
5 answers
59k views

#include "stdafx.h" #include <windows.h> #include <stdio.h> #include <iostream> #include <dos.h> using namespace std; class Dir { public: char* cat; Dir() { ...
Bogdan Tkachenko's user avatar
31 votes
3 answers
107k views

I have a char* array as follows: char *tbl[] = { "1", "2", "3" }; How do I use the sizeof operator to get the number of elements of the array, here 3? The below did work, but is it correct? int n =...
Ayman's user avatar
  • 11.6k
9 votes
4 answers
14k views

I am currently trying to get the length of a dynamically generated array. It is an array of structs: typedef struct _my_data_ { unsigned int id; double latitude; double longitude; unsigned ...
beta's user avatar
  • 2,653
19 votes
2 answers
931 views

I want to write a array containing 16bit integers as raw binary to a file and have tried with the following example: # define __int8_t_defined __intN_t (8, __QI__); __intN_t (16, __HI__); __intN_t (...
TheMeaningfulEngineer's user avatar
11 votes
5 answers
6k views

#include <iostream> using namespace std; int main() { int arr[5] = {5, 8, 1, 3, 6}; int len = *(&arr + 1) - arr; cout << "The length of the array is: " << len; ...
john_w's user avatar
  • 701
4 votes
5 answers
17k views

Is there any way I could find how much bytes are allocated for RandomArray in this code #include<stdio.h> #include<stdlib.h> int main() { int *RandomArray; int n; ...
Rafael's user avatar
  • 79
3 votes
5 answers
3k views

I (think I) understand that you can only retrieve the size of an array (using sizeof) if it is declared at compile time on the stack, e.g. int my_array[] = {1,2,3}; sizeof(my_array) == 3; As soon as ...
bph's user avatar
  • 11.4k
0 votes
4 answers
813 views

i run the following code but it kept printing "4" why its printing "4" and not "12"? and can I use malloc and then sizeof?(if i can then how) #include<stdio.h> int main() { int arr1[3]={1,...
Yuval David's user avatar
3 votes
4 answers
339 views

I have a function, where I use a array of constants: void function(int Id){ int array1[4] = {4 constants}; int array2[4] = {4 constants}; for(int i=0; i<4; i++){ //accessing the array 1&...
SKPS's user avatar
  • 5,858
4 votes
3 answers
8k views

I'm not really versed in C++, but I came to the following code: BaseManager* allManagers[] = { mColorManager, mToolManager, mLayerManager, mPlaybackManager, mViewManager }; for ( ...
sdaau's user avatar
  • 39.1k
1 vote
3 answers
13k views

I am trying to input the rooms, sort them by price and create a text file afterward but there is always an error which I suspect has to do with the sizeof function In some compilers, it will compile ...
Mohammed A's user avatar

15 30 50 per page
1
3 4
5
6 7
12