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

void main() { int *ptr; ptr = (int *) 0x400 ; printf("ptr=%d",ptr); } output?

1 Answers  


What are static variables, and where are they stored?

2 Answers  


main() { int x=20,y=35; x = y++ + x++; y = ++y + ++x; printf("%d %d\n",x,y); }

27 Answers   Advent Global Solutions, CitiGroup, Valeo Lighting Systems India Private Limited, Vishal Transformers, Wipro, Zencer,


Write a program that accept anumber in words

0 Answers  


main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); }

11 Answers   CISOC, CitiGroup, College School Exams Tests,


What is #define used for in c?

0 Answers  


Define a structure to store roll no, name and marks of a student. Using the structure of above write a ‘C’ program to create a file “student.dat”. There must be one record for every student in the file. Accept the data from the user.

0 Answers  


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

0 Answers  


Study the code: void show() main() { show(); } void show (char *s) { printf("%sn",s); } What will happen if it is compiled & run on an ANSI C Compiler? A)It will compile & nothing will be printed when it is executed B)it will compile but not link C)the compiler will generate an error D)the compiler will generate a warning

4 Answers   Accenture,


How can I send mail from within a c program?

0 Answers  


what is level of tree if leaf node is at level 4.please explain.

1 Answers   Wipro,


what is output of the following statetment?Printf(“%x”, -1<<4); ?

5 Answers  


Categories