Posts

Showing posts from April, 2011

#if defined in c

The special operator defined is used in `#if' and `#elif' expressions to test whether a certain name is defined as a macro. defined name and defined (name) are both expressions whose value is 1 if name is defined as a macro at the current point in the program, and 0 otherwise. Thus, #if defined MACRO is precisely equivalent to #ifdef MACRO.
defined is useful when you wish to test more than one macro for existence at once. For example,
#if defined (__vax__) || defined (__ns16000__) would succeed if either of the names __vax__ or __ns16000__ is defined as a macro. Conditionals written like this:
#if defined BUFSIZE && BUFSIZE >= 1024 can generally be simplified to just #if BUFSIZE >= 1024, since if BUFSIZE is not defined, it will be interpreted as having the value zero. If the defined operator appears as a result of a macro expansion, the C standard says the behavior is undefined. GNU cpp treats it as a genuine defined operator and evaluates it normally.

find total subset sums to s

given an array of elements (all elements are unique ) , given a sum s find all the subsets having sum s. for ex array {5,9,1,3,4,2,6,7,11,10} sum is 10 possible subsets are {10}, {6,4}, {7,3}, {5,3,2}, {6,3,1} etc. there can be many more. also find the total number of these subsets.

Understanding endianess

Introduction
To understand the concept of endianness ,you need to be familiar, at a highly abstract level, with memory. All you need to know about memory is that it's one large array. The array contains bytes. In the computer world, people use address to refer to the array locations.
Endianness
The attribute of a system that indicates whether integers are represented with the most significant byte stored at the lowest address (big endian) or at the highest address (little endian).
Each address stores one element of the memory array. Each element is typically one byte. In some memory configurations, each address stores something besides a byte. However, those are extremely rare so, for now, let's make the broad assumption that all memory addresses store bytes.
Storing bytes in memory
I refer to 32 bits, which is the same as four bytes. Integers or single-precision floating point numbers are all 32-bits long. But since each memory address can store a single byte and not four byt…

Declaring Flexible Array Members in structure

I came across this concept while facing one of my interview then thought to share the concept with you all.It may not seem to be big thing for many of us but sometime prove to be handy while declaring variable arrays in  structure.
Any query related to this is highly appreciated.



Flexible array members allow incomplete array struct members without bounds.Consider:#include