< 1 2 3 >   Sort: Rank

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, 8259👍, 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, 7202👍, 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 &amp; ~KBit24;
2007-02-26, 9467👍, 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, 7845👍, 0💬

Multi-dimension Arrays
Write down the equivalent pointer expression for referring the same element a[i][j][k][l]? a[i] == *(a+i) a[i][j] == *(*(a+i)+j) a[i][j][k] == *(*(*(a+i)+j)+k) a[i][j][k][l] == *(*(*(*(a+i)+j)+k)+l)
2007-02-26, 6326👍, 0💬

Strings vs. Character Arrays
What is the difference between strings and character arrays? A major difference is: string will have static storage duration, whereas as a character array will not, unless it is explicity specified by using the static keyword. Actually, a string is a character array with following properties: * the ...
2007-02-26, 6455👍, 0💬

Storage Classes
What are the different storage classes in C? C has three types of storage: automatic, static and allocated. Variable having block scope and without static specifier have automatic storage duration. Variables with block scope, and with static specifier have static scope. Global variables (i.e, file s...
2007-02-26, 6689👍, 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, 7163👍, 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, 6759👍, 0💬

Variable Types
What are the types of variables x, y, y and u defined in the following code? #define Atype int* typedef int *p; p x, z; Atype y, u; Answer: x and z are pointers to int. y is a pointer to int but u is just an integer variable
2007-02-26, 6245👍, 0💬

Conditional Statements
What will happen in these three cases? if (a=0) { //somecode } if (a==0) { //do something } if (a===0) { //do something }
2007-02-26, 6372👍, 0💬

Shift Operations
What will the following piece of code do? int f(unsigned int x) { int i; for (i=0; x!=0; x&gt;&gt;1) { if (x &amp; 0x1) i++; } return i; } Answer: returns the number of ones in the input parameter X.
2007-02-26, 6259👍, 0💬

Conditional Statements
What will be printed as the result of the operation below: main() { int a=0; if (a==0) printf("Cisco Systems\n"); printf("Cisco Systems\n"); } Answer: Two lines with "Cisco Systems" will be printed.
2007-02-26, 6484👍, 0💬

Incremental Operatiors
What will be printed as the result of the operation below: main() { int x=10, y=15; x = x++; y = ++y; printf("%d %d\n",x,y); } Answer: 11, 16
2007-02-26, 6581👍, 0💬

Function Calls
What will be printed as the resultof the operation below: int x; int modifyvalue() { return(x+=10); } int changevalue(int x) { return(x+=1); } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); printf("First output:%d\n",x); x++; changevalue(x); printf("Second output:%d\n",x); modifyva...
2007-02-26, 6511👍, 0💬

Constants
WHat will be the result of the following code? #define TRUE 0 // some code while (TRUE) { // some code } Answer: This will not go into the loop as TRUE is defined as 0.
2007-02-26, 6709👍, 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, 7127👍, 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, 7171👍, 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, 7852👍, 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, 10354👍, 0💬

Function Calls
What will be printed as the result of the operation below: #define swap(a,b) a=a+b;b=a-b;a=a-b; void main() { int x=5, y=10; swap (x,y); printf("%d %d\n",x,y); swap2(x,y); printf("%d %d\n",x,y); } int swap2(int a, int b) { int temp; temp=a; b=a; a=temp; return 0; } The correct answer is 10, 5 5, 10
2007-02-26, 6521👍, 0💬

Shift Operators
What will be printed as the result of the operation below: main() { int x=5; printf("%d,%d,%d\n",x,x&lt ;&lt;2,x&gt;&gt;2) ;} As x = 5 = 0x0000,0101; so x &lt;&lt; 2 -&lt; 0x0001,0100 = 20; x &gt;&gt; 2 -&gt; 0x0000,0001 = 1. Therefore, the answer is 5, 20, 1.
2007-02-26, 6897👍, 0💬

Incremental Operatos
What will be printed as the result of the operation below: main() { int x=20,y=35; x=y++ + x++; y= ++y + ++x; printf("%d%d\n",x,y); } Answer : 5794
2007-02-26, 6564👍, 0💬

Using Pointers
What print out will the folloging code produce? main() { char *p1=“name”; char *p2; p2=(char*)malloc(20); memset (p2, 0, 20); while(*p2++ = *p1++); printf(“%s\n”,p2);> } The pointer p2 value is also increasing with p1 . *p2++ = *p1++ means copy value of *p1 to *p2 , then increment both addresses (p...
2007-02-26, 6473👍, 0💬

< 1 2 3 >   Sort: Rank