Posts

Showing posts from March, 2011

Simple C program of an array of 5 elements without use of Array without memory location

void main() { int *ptr; int i; for(clrscr(),i=0;scanf("%d",&ptr+i),i<5 data-blogger-escaped-br="" data-blogger-escaped-i=""> for(i=0;printf("%d\n",*(&ptr+i)),i<5 data-blogger-escaped-br="" data-blogger-escaped-i=""> getch(); }

Command Line Argument in C

#include int main(int argv,char *argc[]) { clrscr(); printf("%s",argc[1]); printf("\nNo. of arguments %d",argv); return 0; } Here argv - argument vector argc - argument character for execution compile the above program now it will generate an EXE file of that program now in turboc goto dos shell(File->Dos shell) type the name of the program and some argument Example: MyProgram Kunal The output will be Kunal No. of arguments : 2

Use printf without semicolon in simple C program

void main() { if(printf("Hi Kunal")){} } Since printf return non zero value thus this statement is always true
Say Hello

Swapping of two numbers without arithmatic operator without temporary variable

#include<stdio.h> void swap(int *a,int *b) {      *a^=*b^=*a^=*b;  }  int main()  {      int a=10,b=20;      swap(&a,&b);      printf("%d %d",a,b);      getch();      return(0);  }

Microsoft's Interview question Compute(int x) function without loop , without temporary variable without goto,continue

#include<stdio.h> int compute(int x) {     printf("%d ",x);     if(x*2<20000)     printf("%d ",compute(x<<1)>>1);     return x;     } int main() {     compute(1);     getch();     return 0;     }