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

Pointer to Constants
What is the difference between const char* p and char const* p? In const char* p, the character pointed by "p" is constant, so you can not change the value of character pointed by p but u can make "p" refer to some other location. In char const* p, the pointer "p" is constant not the character refer...
2007-02-26, 6614👍, 0💬

Conditional Statements
What will happen in these three cases? if (a=0) { //somecode } if (a==0) { //do something } if (a===0) { //do something }
2007-02-26, 6589👍, 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, 6514👍, 0💬

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, 6494👍, 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, 6456👍, 0💬

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, 6444👍, 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, 6428👍, 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, 6380👍, 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, 6323👍, 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, 6322👍, 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, 5178👍, 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, 4622👍, 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, 4122👍, 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, 2817👍, 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, 2473👍, 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, 2204👍, 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, 2117👍, 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, 2094👍, 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, 2078👍, 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, 2059👍, 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, 2040👍, 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, 1986👍, 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, 1928👍, 0💬

How can I shut off the warning: possible pointer alignment problem ...
How can I shut off the ``warning: possible pointer alignment problem'' message which lint gives me for each call to malloc? A modern lint shouldn't be complaining about this. Once upon a time, lint did not and could not know that malloc ``returns a pointer to space suitably aligned for storage of an...
2016-06-03, 1914👍, 0💬

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