main(){
printf(”%x”,-1
Entries Tagged as 'C/C++'
Representation of negative numbers
October 6th, 2006 · No Comments · C/C++, Placements
Tags:
extern, static variables, enum, register
October 6th, 2006 · No Comments · C/C++, Placements
Static variable
When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively.
extern storage class in the following declaration,
extern int i;
specifies to the compiler that the memory […]
Tags:
Complete binary tree and Full binary tree
October 6th, 2006 · No Comments · C/C++
Full and Complete binary trees are different. All full binary trees are complete binary trees but not vice versa.
Full binary tree needs 2^n-1 nodes
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Tags:
Redefining inbuilt data types
October 6th, 2006 · No Comments · C/C++
#include
typedef int INTEGER /* will work */
But
#define INTEGER int /* will also work*/
INTEGER SomeFunction()
{
…… code
return 0;
}
This will work
But Rule of thumb is
#defines are used for textual replacement whereas typedefs are used for introducing new names.
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Tags:
sizeof operator
October 6th, 2006 · No Comments · C/C++
sizeof(’a’) = 4
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Tags:
Index into arrays
October 6th, 2006 · No Comments · C/C++
main ()
{
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Tags:
Function pointers, static char
October 6th, 2006 · No Comments · C/C++
typedef int abc (int a, char *b);
int func2 (int a, char *b){
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Tags:
Macros
October 6th, 2006 · No Comments · C/C++
Macro to swap any two variable int, char, float, struct etc..
/* Generic Swap macro*/
#define swap (a, b, type) {type t = a; a = b; b = t; }
Call the macro like this:
swap(a,b,int)
swap(a,b,str)
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Tags:
String initialization
October 6th, 2006 · No Comments · C/C++
char *a = “Hi how are you??”
a[0] = ‘h’;
This will output Segmentation fault
Because, such an intialization will create const memory and it can’t be modified.
While
char a[] = “Hi how are you??”
a[0] = ‘h’
will give the desired output.
Bookmark it!
These icons link to social bookmarking sites where readers can share and discover new web pages.
Tags:
More on structures and unions
October 6th, 2006 · No Comments · C/C++
typedef does not define a new data type
There are three main reasons for using typedefs:
* It makes the writing of complicated declarations a lot easier. This helps in eliminating a lot of clutter in the code.
* It helps in achieving portability in programs. That is, if we use typedefs for data types that are machine […]
Tags:















