Category : c

Q(Question): Why does this program print 1 for a[-1]. I thought it should be an OOB access situation! #include <stdio.h> #include <stdlib.h> int main() { int a[6]={1,2,3,4,5}; printf("%d\n", a[-1]); return EXIT_SUCCESS; } Thanks, Vijay Zanvar http://faq.zanvar.in A(Answer): "Vijay Kumar R. Zanvar" <vi*****@gmail.comwrites: Why does this program print 1 for a[-1]. I thought it should be ..

Read more

Q(Question): Are the following guaranteed to work always as *C90* code? 1. #include <stdio.h> void some_func(int *p, const size_t SIZE) { size_t i; for(i=0; i<SIZE; ++i) printf("%d ", p[i]); } int main(void) { int array[10][5]= {0}; some_func(array[0], sizeof(array)/sizeof(**array)); puts(""); return 0; } The above prints 50 zeros. I think it is guaranteed to work, since ..

Read more

Q(Question): Has anyone here got access to a ridiculous computer? Something like: CHAR_BIT == 9 PADDING_BITS(int) != 0 NUMBER_SYSTEM == SIGN_MAGNITUDE Null pointer bit pattern == All ones I’m writing some fully-portable code and would love to actually compile it for, and test it on, a very strange machine 😀 Or does anyone know of ..

Read more

Q(Question): I’m told that "#pragma once" has made it into the ISO standard for either C or C++. I can’t find any reference to that anywhere. If it’s true, do any of you have a reference I can use? Thanks… A(Answer): Rick <re****************@spam.nowrote in news:h9********************************@4ax.com: > I’m told that "#pragma once" has made it into ..

Read more

Q(Question): Hi, When you define varibles in the middle of your function call (C99), such as: if(i == 5) { int x = 5; int z = 2; } Are they allocated on the stack as they’re encountered at run-time or are they allocated before, along with the arguments and initial variable declarations? Is a ..

Read more

Q(Question): Hi ALL, I am new to C and programming . I need suggestions for the IDE to be used as a begginer and should I start on Windows or Linux ?? I am also looking for resources for C programming on Internet with examples on each concept. I appreciate if any one can help ..

Read more

Q(Question): Hi, I’m wondering if anyone knows if the following function will function properly as a set-bit counter on non 2s complement machines (as K&R2 implies). | int bitcount(unsigned x) | { | int count; | | for(count = 0; x != 0; count++, x &= (x-1)) | ; | | return count; | } ..

Read more

Q(Question): hi all, What will happen when I tries to input a character from a file which is finished, in other words what will ‘c’ contains after the last statement in the following code is executed : FILE * file =fopen("FILE1.c","r"); char c; while((c=fgetc(file)) != EOF); c=fgetc(file); // what is value of c now??????????????????? Thanks, ..

Read more

Q(Question): Hi there, Does the ANSI standard say anything about incrementing variables past their limits ? When I compile code like this: unsigned char x = 255; x++; printf ( "%d\n", x ); with GCC, the output is 0. From an assembly point of view this seems to be logical behaviour, but is it defined ..

Read more

Q(Question): Hello all, I’m very new to C but I have a number of years of Common Lisp programming experience. I’m trying to figure out ways of translating higher order concepts such as closures into C. The code will not be idiomatic C. GCC has an extension to ISO C that permits nested functions: <http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html> ..

Read more