Wednesday 13 March 2013

EOF as variable name


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

Compilation error

Explanation: Variable name cannot be pre defined function of included header file.


Blog Author: Vijay Kumar

Go to: Java Aptitude

printf as Variable name


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

Compilation error

Explanation: Variable name cannot be pre defined function of included header file.


Blog Author: Vijay Kumar

Go to: Java Aptitude

Different variable scope 3



#include<stdio.h>
int main(){
    struct a{
         int a;
    };
    struct a b={10};
    printf("%d",b.a);
    return 0;
}
output: 10

Explanation: Two variables can have same name in different scope.


Blog Author: Vijay Kumar

Go to: Java Aptitude

main as variable Name


#include<stdio.h>
int main(){
    int main = 80;
    printf("%d",main);
    return 0;
}
80
Explanation:
Variable name can be main.


Blog Author: Vijay Kumar

Go to: Java Aptitude

Different variable scope 2


#include<stdio.h>
int main(){
    int xyz=20;{
         int xyz=40;
    }
    printf("%d",xyz);
    return 0;
}
20
Explanation:
Two variables can have same name in different scope.


Blog Author: Vijay Kumar

Go to: Java Aptitude

different variable scope


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

output: 20

Explanation: Two variables can have same name in different scope.


Blog Author: Vijay Kumar

Go to: Java Aptitude

Global Variable same name 3


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

output: 25

Explanation:
Two or more global variables can have same name but we can initialize only one of them.


Blog Author: Vijay Kumar

Go to: Java Aptitude

Simple struct code


void main()
{
struct india
{
char c;
float d;
};
struct world
{
int a[3];
char b;
struct india orissa;
};
struct world st ={{1,2,3},'P','q',1.4};
clrscr();
printf("%d\t%c\t%c\t%f",st.a[1],st.b,st.orissa.c,st.orissa.d);
getch();
}

Output: 2 p q 1.400000


Blog Author: Vijay Kumar

Go to: Java Aptitude

Global Variables same name 2

#include<stdio.h>
static num=5;
extern int num;

int main()
{
    printf("%d",num);
    return 0;
}
int num =25;

Compilation error

Explanation:
Two or more global variables can have same name but we can initialize only one of them.


Blog Author: Vijay Kumar

Go to: Java Aptitude

Global variables with same name


#include<stdio.h>
static num=5;
int num;
extern int num;

int main()
{
    printf("%d",num);
    return 0;
}

output: 5
Explanation:
Two or more global variables can have same name but we can initialize only one of them.


Blog Author: Vijay Kumar

Go to: Java Aptitude