<< < 1 2 3 4 5 6 7 8 > >>   Sort: Date

Determing the Size of Allocated Memory Blocks
How can you determine the size of an allocated portion of memory? You can't, really. free() can , but there's no way for your program to know the trick free() uses. Even if you disassemble the library and discover the trick, there’s no guarantee the trick won’t change with the next release of the co...
2007-02-26, 6348👍, 0💬

Multi-dimension Arrays
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]? a[i] == *(a+i) a[i][j] == *(*(a+i)+j) a[i][j][k] == *(*(*(a+i)+j)+k) a[i][j][k][l] == *(*(*(*(a+i)+j)+k)+l)
2007-02-26, 6337👍, 0💬

What is wrong with this initialization?
What's wrong with this initialization? char *p = malloc(10); My compiler is complaining about an ``invalid initializer'', or something. Is the declaration of a static or non-local variable? Function calls are allowed in initializers only for automatic variables (that is, for local, non-static variab...
2020-08-03, 6335👍, 2💬

💬 2020-08-03 chelseaclark: Evidence for GPCR dimerization comes from biochemical, biophysical and functional studies. https://dda.creative-bioarray.com/re c...

💬 2020-05-27 james: very helpful thanks

Calling Base Class Methods
How can method defined in multiple base classes with same name be invoked from derived class simultaneously? class x { public: m1(); }; class y { public: m1(); }; class z: public x, public y { public: m1() { x::m1(); y::m1(); } };
2007-02-26, 6293👍, 0💬

Shift Operations
What will the following piece of code do? int f(unsigned int x) { int i; for (i=0; x!=0; x&gt;&gt;1) { if (x &amp; 0x1) i++; } return i; } Answer: returns the number of ones in the input parameter X.
2007-02-26, 6267👍, 0💬

Determining If Symbols Are Defined or Not
How can you check to see whether a symbol is defined? You can use the #ifdef and #ifndef preprocessor directives to check whether a symbol has been defined (#ifdef) or whether it has not been defined (#ifndef). Can you define which header file to include at compile time? Yes. This can be done by usi...
2007-02-26, 6261👍, 0💬

Variable Types
What are the types of variables x, y, y and u defined in the following code? #define Atype int* typedef int *p; p x, z; Atype y, u; Answer: x and z are pointers to int. y is a pointer to int but u is just an integer variable
2007-02-26, 6253👍, 0💬

Swapping Variables
Can you write a program to interchange 2 variables without using the third one? a = 7; b = 2; a = a + b; b = a - b; a = a - b;
2007-02-26, 6180👍, 0💬

Opening Files to Share with Other Programs
How can I open a file so that other programs can update it at the same time? Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special program named SHARE...
2007-02-26, 6159👍, 0💬

How can I construct preprocessor if expressions which compare strings?
How can I construct preprocessor if expressions which compare strings? You can't do it directly; preprocessor #if arithmetic uses only integers. An alternative is to #define several macros with symbolic names and distinct integer values, and implement conditionals on those: #define RED 1 #define BLU...
2016-02-05, 5195👍, 0💬

C question
What is the difference between: myObj *x = new myObj[100]; delete x; and myObj *x = new myObj[100]; delete [] x;
2009-07-16, 5042👍, 0💬

How can i trap the arrow keys inside the timer program?
How can i trap the arrow keys inside the timer program? How do you trap arrow keys in a regular program? What makes a timer program special?
2009-04-19, 4524👍, 0💬

About listing of the process
how to write a .c program in unix ,like I want to list the process information when I give the process id.
2010-04-07, 4041👍, 0💬

How can I convert numbers to strings (the opposite of atoi)? Is there an itoa function?
How can I convert numbers to strings (the opposite of atoi)? Is there an itoa function? Just use sprintf: sprintf(string, "%d", number); (Don't worry that sprintf may be overkill, potentially wasting run time or code space; it works well in practice.) You can obviously use sprintf to convert long or...
2015-08-24, 2588👍, 0💬

In a call to malloc, what does an error like
In a call to malloc, what does an error like ``Cannot convert `void *' to `int *''' mean? It means you're using a C++ compiler instead of a C compiler.
2016-06-21, 2308👍, 0💬

I im trying to declare a pointer and allocate some space for it
I'm trying to declare a pointer and allocate some space for it, but it's not working. What's wrong with this code? char *p; *p = malloc(10); The pointer you declared is p, not *p. When you're manipulating the pointer itself (for example when you're setting it to make it point somewhere), you just us...
2016-06-10, 2075👍, 0💬

I see code like ...
I see code like char *p = malloc(strlen(s) + 1); strcpy(p, s); Shouldn't that be malloc((strlen(s) + 1) * sizeof(char))? It's never necessary to multiply by sizeof(char), since sizeof(char) is, by definition, exactly 1. (On the other hand, multiplying by sizeof(char) doesn't hurt, and in some circum...
2016-06-21, 1990👍, 0💬

How can I find out how much memory is available?
How can I find out how much memory is available? Your operating system may provide a routine which returns this information, but it's quite system-dependent. (Also, the number may vary over time.) If you're trying to predict whether you'll be able to allocate a certain amount of memory, just try it-...
2016-04-23, 1953👍, 0💬

I wrote a little wrapper around malloc ...
I wrote a little wrapper around malloc, but it doesn't work: #include lt;stdio.h> #include lt;stdlib.h> mymalloc(void *retp, size_t size) { retp = malloc(size); if(retp == NULL) { fprintf(stderr, "out of memory\n"); exit(EXIT_FAILURE); } } Are you sure the function initialized what you thought it di...
2016-06-10, 1932👍, 0💬

How can I dynamically allocate arrays?
How can I dynamically allocate arrays? The equivalence between arrays and pointers allows a pointer to malloc'ed memory to simulate an array quite effectively. After executing #include &lt;stdlib.h> int *dynarray; dynarray = malloc(10 * sizeof(int)); (and if the call to malloc succeeds), you can...
2016-04-23, 1921👍, 0💬

What is the difference between fgetpos/fsetpos and ftell/fseek? What are fgetpos and fsetpos good for?
What is the difference between fgetpos/fsetpos and ftell/fseek? What are fgetpos and fsetpos good for? ftell and fseek use type long int to represent offsets (positions) in a file, and may therefore be limited to offsets which can be represented in a long int. (Type long int is not guaranteed to hol...
2015-10-14, 1877👍, 0💬

What does it mean?
Is char a[3] = "abc"; legal? What does it mean? It is legal in ANSI C (and perhaps in a few pre-ANSI systems), though useful only in rare circumstances. It declares an array of size three, initialized with the three characters 'a', 'b', and 'c', without the usual terminating '\0' character. The arra...
2015-12-09, 1870👍, 0💬

I have heard that some operating systems dont actually allocate...
I've heard that some operating systems don't actually allocate malloc'ed memory until the program tries to use it. Is this legal? It's hard to say. The Standard doesn't say that systems can act this way, but it doesn't explicitly say that they can't, either. (Such a ``deferred failure'' implementati...
2016-04-21, 1803👍, 0💬

malloc is returning crazy pointer values ...
malloc is returning crazy pointer values, I have included the line extern void *malloc(); before I call it. malloc accepts an argument of type size_t, and size_t may be defined as unsigned long. If you are passing ints (or even unsigned ints), malloc may be receiving garbage (or similarly if you are...
2016-04-15, 1795👍, 0💬

<< < 1 2 3 4 5 6 7 8 > >>   Sort: Date