1 2 3 4 5 6 > >>   Sort: Date

printf() and sprint() Functions
What is the difference between "printf(...)" and "sprintf(...)"? sprintf(...) writes data to the charecter array whereas printf(...) writes data to the standard output device.
2007-02-26, 16282👍, 0💬

Regarding C Coding
Regarding C Coding Given: Line in file Contents 30 int * someIDs, theFirst, *r; 110 someIDs =GetSomeIDs(); /* defined below */ 111 theFirst = someIDs [0]; 112 r= ReorderIDs(someIDs); 113-150 /* we want to use ‘theFirst’ and ‘r’ here*/ 499 /*-------- GetSomeIDs-----*/ 500 int * GetSomeIDs() 501 { 50...
2010-05-12, 9330👍, 0💬

enum vs. define Statements
What is the benefit of using an enum rather than a #define constant? The use of an enumeration constant (enum) has many advantages over using the traditional symbolic constant style of #define. These advantages include a lower maintenance requirement, improved program readability, and better debuggi...
2007-02-26, 9046👍, 0💬

Bitwise Operations
Which bit wise operator is suitable for turning off a particular bit in a number? The bitwise AND operator. Here is an example: enum { KBit1 = 0x00000001 KBit2 = 0x00000010, KBit3 = 0x00000100, ... }; some_int = some_int & ~KBit24;
2007-02-26, 8584👍, 0💬

"register" Modifier
When should the register modifier be used? Does it really help? The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU's registers, if possible, so that it can be accessed faster. There are several restrictions on the use of the register modi...
2007-02-26, 8313👍, 0💬

printf() Function
What is the output of printf("%d")? 1. When we write printf("%d",x); this means compiler will print the value of x. But as here, there is nothing after "%d", so compiler will show in output window gurbage value. 2. When we use %d the compiler internally uses it to access the argument in the stack (a...
2007-02-26, 7013👍, 0💬

calloc() and malloc() Functions
What is the difference between "calloc(...)" and "malloc(...)"? 1. calloc(...) allocates a block of memory for an array of elements of a certain size. By default the block is initialized to 0. The total number of memory allocated will be (number_of_elements * size). malloc(...) takes in only a singl...
2007-02-26, 6978👍, 0💬

Convert an integer or a float to a string
Does there exist any other function which can be used to convert an integer or a float to a string? Some implementations provide a nonstandard function called itoa(), which converts an integer to string. char *itoa(int value, char *string, int radix); DESCRIPTION - The itoa() function constructs a s...
2007-02-26, 6948👍, 0💬

Reducing the Final Size of an Executable File
How to reduce the final size of an executable file? Size of the final execuatable can be reduced using dynamic linking for libraries.
2007-02-26, 6819👍, 0💬

String Pointers
What will be printed as the result of the operation below: main() { char *ptr = " Cisco Systems"; *ptr++; printf("%s\n",ptr); ptr++; printf("%s\n",ptr); } 1) ptr++ increments the ptr address to point to the next address. In the prev example, ptr was pointing to the space in the string before C, now ...
2007-02-26, 6627👍, 0💬

"union" Data Type
What's the output of the following program? And why? #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,"hello"); x.c = 21.50; printf("Union x : %d %s %f n",x.a,x.b,x.c); printf("Union y : %d %s %f n",y.a,y.b,y.c); }
2007-02-26, 6620👍, 0💬

Deteting Circular Linked List
Can you tell me how to check whether a linked list is circular? Create two pointers, and set both to the start of the list. Update each as follows: while (pointer1) { pointer1 = pointer1->next; pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next ;if (pointer1 == poi...
2007-02-26, 6574👍, 0💬

Bitwise Operations
Which bit wise operator is suitable for checking whether a particular bit is on or off? The bitwise AND operator. Here is an example: enum { KBit1 = 0x00000001 KBit2 = 0x00000010, KBit3 = 0x00000100, ... }; if ( some_int & KBit24 ) printf("Bit number 24 is ON\n"); else printf("Bit number 24 is O...
2007-02-26, 6483👍, 0💬

Can Static Variables Be Declared in Header Files
Can static variables be declared in a header file? You can't declare a static variable without defining it as well (this is because the storage class modifiers static and extern are mutually exclusive). A static variable can be defined in a header file, but this would cause each source file that inc...
2007-02-26, 6395👍, 0💬

Macro vs. Function
Advantages of a macro over a function? Macro gets to see the Compilation environment, so it can expand __DATE__ __TIME__ __FILE__ #defines. It is expanded by the preprocessor. For example, you can't do this without macros. #define PRINT(EXPR) printf( #EXPR "=%d\n", EXPR) PRINT( 5+6*7 ) // expands in...
2007-02-26, 6362👍, 0💬

What Is C Language
What Is C Language? The C programming language is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages. C...
2007-02-26, 6356👍, 0💬

Address of the First Element of an Array
When does the compiler not implicitly generate the address of the first element of an array? Whenever an array name appears in an expression such as: array as an operand of the sizeof operator array as an operand of & operator array as a string literal initializer for a character array Then ...
2007-02-26, 6248👍, 0💬

Printing Permutaions of a String
Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. void PrintPermu (char *sBegin, char* sRest) { int iLoop; char cTmp; char cFLetter[1]; char *sNewBegin; char *sCur; int iLen; static int iCount; iLen = strlen(sRest); i...
2007-02-26, 6184👍, 0💬

"const" and "volatile"
Can a variable be both const and volatile? Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, a timer structure can be accessed through a volatile const pointer. The f...
2007-02-26, 6092👍, 0💬

What does static variable mean
What does static variable mean? There are 3 main uses for static variables: If you declare within a function, it retains the value between function calls. If it is declared for a function name, by default function is extern. So it will be visible from other files. If the function declaration is as s...
2007-02-26, 6016👍, 0💬

Character Array
What will be printed as the result of the operation below: main() { char s1[]="Cisco"; char s2[]="systems"; printf("%s",s1); } Answer: Cisco
2007-02-26, 5963👍, 0💬

Modulation Operations
Write an equivalent expression for x%8? x&7
2007-02-26, 5960👍, 0💬

Including Source Files
What is the result of using Option Explicit? When writing your C program, you can include files in two ways. The first way is to surround the file you want to include with the angled brackets < and >. This method of inclusion tells the preprocessor to look for the file in the predefine...
2007-02-26, 5906👍, 0💬

Nesting Include Files
Can include files be nested? The answer is yes. Include files can be nested any number of times. As long as you use precautionary measures , you can avoid including the same file twice. In the past, nesting header files was seen as bad programming practice, because it complicates the dependency trac...
2007-02-26, 5899👍, 0💬

1 2 3 4 5 6 > >>   Sort: Date