can we declare a variable in different scopes with different
data types? answer in detail

Answers were Sorted based on User's Feedback



can we declare a variable in different scopes with different data types? answer in detail..

Answer / rajasekhar

yes we can declare the same variable with different data types in different scopes...


y bcoz as the scope ends the availability of that particular variable also ends..

so, if u create a variable which is declared in the another scope there will be no error...


ex: void main()
{
int a;
}/*the availability of a has ended here*/
int print()
{
char a;

return 0;
}/* as this is next scope, the variabla declared in the main function does not affect this function*/


hope u understood



thank u

Is This Answer Correct ?    7 Yes 0 No

can we declare a variable in different scopes with different data types? answer in detail..

Answer / tatukula

Yes,
why because that variable scope is ends with in that block only...

int main()
{
int a=20;
printf("%d\n",a);

{
char a='c';
printf("%c\n",a);
}
printf("%d\n",a);
}

output: 20 c 20

Is This Answer Correct ?    0 Yes 0 No

can we declare a variable in different scopes with different data types? answer in detail..

Answer / palani222samy

ya we can declare, ex: int array b[],
char array c[]

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Interview Questions

What are the uses of a pointer?

0 Answers  


what is data structure

5 Answers   Maveric, TCS,


What is extern keyword in c?

0 Answers  


What is a pointer value and address in c?

0 Answers  


input may any number except 1,output will always 1.. conditions only one variable should be declare,don't use operators,expressions,array,structure

4 Answers   IBM,






What is the use of function overloading in C?

0 Answers   Ittiam Systems,


There are 3 baskets of fruits with worng lables,one basket has apple,another basket has orange,another has combination of apple and orange,what is the least way of interchange the lables.

15 Answers   Cisco, Google, MBT,


what does the following code do? fn(int n,int p,int r) { static int a=p; switch(n){ case 4:a+=a*r; case 3:a+=a*r; case 2:a+=a*r; case 1:a+=a*r; } } a.computes simple interest for one year b.computes amount on compound interest for 1 to 4 years c.computes simple interest for four year d.computes compound interst for 1 year

7 Answers   TCS,


Is int a keyword in c?

0 Answers  


What are the rules for identifiers in c?

0 Answers  


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

1 Answers   IBM,


What are pointers?

0 Answers   Accenture, Tavant Technologies, Zensar,


Categories