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, 17765👍, 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, 10711👍, 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, 10618👍, 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, 10519👍, 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, 9699👍, 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, 9306👍, 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, 8438👍, 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, 8313👍, 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, 8122👍, 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, 8106👍, 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, 8035👍, 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, 8005👍, 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, 7805👍, 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, 7798👍, 0💬

How can I implement a variable field width with printf?
How can I implement a variable field width with printf? That is, instead of something like %8d, I want the width to be specified at run time. printf("%*d", width, x) will do just what you want. The asterisk in the format specifier indicates that an int value from the argument list will be used for t...
2021-01-21, 7698👍, 1💬

💬 2021-01-21 John Doe: Hello

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

Bitwise Operations
Which bit wise operator is suitable for turning on a particular bit in a number? The bitwise OR operator. In the following code snippet, the bit number 24 is turned ON: enum { KBit1 = 0x00000001 KBit2 = 0x00000010, KBit3 = 0x00000100, ... }; some_int = some_int | KBit24;
2007-02-26, 7418👍, 0💬

String Concatenation
What will be printed as the result of the operation below: main() { char *p1; char *p2; p1=(char *)malloc(25); p2=(char *)malloc(25); strcpy(p1,"Cisco"); strcpy(p2,"systems"); strcat(p1,p2); printf("%s",p1); } Answer: Ciscosystems
2007-02-26, 7368👍, 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, 7363👍, 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, 7346👍, 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, 7342👍, 0💬

How can I construct preprocessor if expressions which compare strings?
How can I construct preprocessor if expressions which compare strings? You can't do it directly; preprocessor #if arithmetic uses only integers. An alternative is to #define several macros with symbolic names and distinct integer values, and implement conditionals on those: #define RED 1 #define BLU...
2016-02-05, 7332👍, 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, 7320👍, 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, 7302👍, 0💬

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