Skip to content

Instantly share code, notes, and snippets.

@sharmaeklavya2
Last active April 1, 2017 16:05
Show Gist options
  • Save sharmaeklavya2/9bfca11149eb3fa915b18e97e8b0684f to your computer and use it in GitHub Desktop.
Save sharmaeklavya2/9bfca11149eb3fa915b18e97e8b0684f to your computer and use it in GitHub Desktop.
Anti-Coding 2015 Problems - Round 1

1

What will be the output?

#include <stdio.h>
int main(){
    int c=5;
    printf("%d",main||c);
    return 0;
}
  1. Runtime Error
  2. 5
  3. 1
  4. 0
  5. Compilation Error

2

#include<stdio.h>
int main(){
    const int *p=5;
    int a=10;
    p=&a;
    printf("%d",*p);
    return 0;
}
  1. 0
  2. 10
  3. Garbage value
  4. Any memory address
  5. Error: cannot modify constant object

3

#include <stdio.h>
int main(){
    signed x;
    unsigned y;
    x=10+-10u+10u+-10;
    y=x*x;
    if(y==x){
        printf("%d %d",x,y);
    }else{
        printf("%u %u",x,y);
    }
    return 0;
}
  1. -10 100
  2. 0 0
  3. 10 100
  4. Compilation Error

4

#include<stdio.h>
int main(){
int goto=5;
printf("%d",goto);
return 0;
}
  1. 5
  2. Runtime Error
  3. Compilation error
  4. None of these

5

#include <stdio.h>
int main(){
    char arr[10];
arr="world";
printf("%s",arr);
return 0;
}
  1. world
  2. w
  3. NULL
  4. Compilation Error
  5. None of the Above. (Specify)

6

Insert appropriate condition to print "Helloworld"

#include <stdio.h>
int main(){
    if(____){
        printf("Hello");
    }else{
        printf("world");
    }
    return 0;
}

7

#include <stdio.h>
main(){
    float a=1.1;
    double b=1.1;
    if(a<1.1){
        printf("1y");
    }else{
        printf("1n");
    }
    if(b<1.1){
        printf("2y");
    }else{
        printf("2n");
    }
    if(a==b){
        printf("3y");
    }else{
        printf("3n");
    }
    return 0;
}

8

#include <stdio.h>
int main(){
    static int a=5;
    printf("%d ",a--);
    if(a){
main();
    }
}

9

#include <stdio.h>
int main(){
    extern int a;
    a=20;
    printf("%d",a);
    return 0;
}
  1. 20
  2. Stack Overflow error
  3. Memory Linking error (undefined reference)

10

int main(){
    int i=10;
static int x=I;
    if(x==i){
    printf("Equal");
    }else if(x>i){
        Printf("Greater than");
    }else{
        Printf("less than");
    }
}
  1. Equal
  2. Greater than
  3. Less than
  4. Compilation Error
  5. Runtime Error

11

#include <stdio.h>
int main(){
int v=1024;
    v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
v >>= 1;
printf("%d",v);
}

What is the output? What if instead of fixed value of ‘v’, I decide to take a user input value?

12

#include<stdio.h>
int main(){
    int c=- -2;
    printf("%d",c);
    return 0;
}

13

#define square(x) x*x
#include <stdio.h>
int main(){
    int a;
    a=64/square(4);
    printf("%d",a);
    return 0;
}

14

#include <stdio.h>
int main(){
    int i=0;
    for(;i++;printf("%d",i--));
    printf("%d",i);
    return 0;
}
  1. 0
  2. 1
  3. 11111111111...
  4. 00000000000...

15

#include <stdio.h>
int main(){
int i=-1;
for(;i++;printf("%d",++i),i--);
printf("%d",--i);
return 0;
}
  1. 00
  2. 10
  3. 11111111111...
  4. 00000000000...
  5. 11

16

#include <stdio.h>
int main(){
int a=(1<<4);
    int b=(1<<10);
    a^=b^=a^=(b^=a);
    a-=b;
printf("%d",(a/b)>>4);
}
  1. 0
  2. 4
  3. 16
  4. 64
  5. 256
  6. 1024

17

#include <stdio.h>
int main(){
int a=1684;
    int b=1684351;
    a^=b^=a^=b;
printf("%d %d",a,b);
}
  1. 0 0
  2. 1684 1684
  3. 1684351 1684351
  4. 1684351 1684
  5. 1684 1684351

18

#include <stdio.h>
int main()
{
        int a=25;
        printf("%d\n",printf("%d",printf("%d",a)));
        return 0;
}
  1. 252525
  2. 2521
  3. 2511
  4. 25
  5. Runtime Error

19

#include<stdio.h>
int main(){
    int n=5;
switch(n){
    int r=6;
    case 5: printf("%d",r);
        break;
    default: printf("%d",r);
        break;
}
return 0;
}
  1. Compilation error
  2. 6
  3. 5
  4. Garbage Value

20

#include <stdio.h>
#define NUMBER_OF_ELEMENTS (sizeof(array)/sizeof(array[0]))
int array[]={7,6,5,4,3,2,1};
int main(){
    printf("Hello AntiCoder!\n");
    int num;
    for(num=-1; num<=(NUMBER_OF_ELEMENTS+2); num++){
        printf("%d\n",array[num+1]);
}
    printf("Hello AntiCoder!\n");
    return 0;
}
  1. Hello AntiCoder!
    Hello AntiCoder!
  2. Hello AntiCoder!
    7
    6
    5
    4
    3
    2
    1
    0
    0
    0
    0
    Hello AntiCoder!
  3. Hello AntiCoder!
    7
    6
    5
    4
    3
    2
    1
  4. Runtime Error
  5. Compile Time Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment