Tuesday 12 March 2013

int abcdefghijklmnopqrstuvwxyz123456789=10;


#include<stdio.h>
int main(){
    int abcdefghijklmnopqrstuvwxyz123456789=10;
    int abcdefghijklmnopqrstuvwxyz123456=40;
    printf("%d",abcdefghijklmnopqrstuvwxyz123456);
    return 0;
}
Compilation error

Explanation: Only first 32 characters are significant in variable name. So compiler will show error: Multiple declaration of identifier abcdefghijklmnopqrstuvwxyz123456.


Blog Author: Vijay Kumar

Go to: Java Aptitude

class, public and private as variables


#include<stdio.h>
int main(){
    int class=150;
    int public=25;
    int private=30;
    class = class >> private - public;
    printf("%d",class);
    return 0;
}

Output: 4

Explanation: Variable name can be keyword of c++ in c.


Blog Author: Vijay Kumar

Go to: Java Aptitude

int max-val=100;


#include<stdio.h>
int main(){
    int max-val=100;
    int min-val=10;
    int avg-val;
    avg-val = max-val + min-val / 2;
    printf("%d",avg-val);
    return 0;
}
Compilation error

explanation: We cannot use special character – in the variable name.


Blog Author: Vijay Kumar

Go to: Java Aptitude

underscore as variable


#include<stdio.h>
int main(){
    int _=5;
    int __=10;
    int ___;
    ___=_+__;
    printf("%i",___);
    return 0;
}

output: 15

Explanation: Variable name can have only underscore.


Blog Author: Vijay Kumar

Go to: Java Aptitude

long int 1a=5l;


#include<stdio.h>
int main(){
long int 1a=5l;
printf("%ld",1a);
    return 0;
}
Compilation error

Invalid variable name. Variable name must star from either alphabet or underscore.


Blog Author: Vijay Kumar

Go to: Java Aptitude

int goto=5;


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

Compilation error

Explanation:
Invalid variable name. goto is keyword in c. variable name cannot be any keyword of c language.


Blog Author: Vijay Kumar

Go to: Java Aptitude