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

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

Static Variables
The following variable is available in file1.c, who can access it? static int average; Answer: all the functions in the file1.c can access the variable.
2007-02-26, 5683👍, 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, 5681👍, 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, 5673👍, 0💬

Incremental Operatiors
What will be printed as the result of the operation below: main() { int x=10, y=15; x = x++; y = ++y; printf("%d %d\n",x,y); } Answer: 11, 16
2007-02-26, 5666👍, 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, 5635👍, 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, 5620👍, 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, 4527👍, 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, 4149👍, 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, 3633👍, 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-05-27, 1984👍, 1💬

💬 2020-05-27 james: very helpful thanks

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, 1527👍, 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, 1504👍, 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, 1382👍, 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, 1379👍, 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, 1336👍, 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, 1314👍, 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, 1289👍, 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, 1246👍, 0💬

Return a null pointer or a pointer to 0 bytes? .....
What should malloc(0) do? Return a null pointer or a pointer to 0 bytes? The ANSI/ISO Standard says that it may do either; the behavior is implementation-defined ortable code must either take care not to call malloc(0), or be prepared for the possibility of a null return.
2016-04-21, 1239👍, 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, 1195👍, 0💬

How can I read a single character from the keyboard without waiting for the RETURN key?
How can I read a single character from the keyboard without waiting for the RETURN key? How can I stop characters from being echoed on the screen as they're typed? Alas, there is no standard or portable way to do these things in C. Concepts such as screens and keyboards are not even mentioned in the...
2015-04-29, 1176👍, 0💬

What's the best way to write a multi-statement macro?
What's the best way to write a multi-statement macro? The usual goal is to be able to invoke the macro as if it were an expression statement consisting of a function call: MACRO(arg1, arg2); This means that the ``caller'' will be supplying the final semicolon, so the macro body should not. The macro...
2016-02-22, 1146👍, 0💬

I need a random number generator.
I need a random number generator. The Standard C library has one: rand. The implementation on your system may not be perfect, but writing a better one isn't necessarily easy, either. Here is a portable C implementation of the ``minimal standard'' generator : #define a 16807 #define m 2147483647 #def...
2015-08-03, 1136👍, 0💬

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