Cognzant Technology Solutions Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
5
of 5 vote

Default value for a global variable is 0

- Saurabh Singhal August 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

As far as my knowledge the default value of global variable is garbage.
I think u r right. Bt in this context I have one question that,
Uninitalized global variable stored in bss segment and the initialized global variables stored in data segment. Then if the compiler autmatically sets the value of global variable to Zero. Then what is the requiremnt of bss segment. And what is the use of "static" keyword, as it also does the same, if both have declared in the same file. Look at the below example;

int i;//Compiler sets the value to Zero.
int j = 0;// Here user sets to Zero.
static int k;//Default is Zero
main()
{
printf("%d...%d...%d",i, j, k);
}

What makes the difference in the above program?

- rasmiranjanbabu August 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The .bss segment is an optimization. The entire .bss segment is described by a single number, probably 4 bytes or 8 bytes, that gives its size in the running process, whereas the .data section is as big as the sum of sizes of the initialized variables. Thus, the .bss makes the executables smaller and quicker to load. Otherwise, the variables could be in the .data segment with explicit initialization to zeroes; the program would be hard-pressed to tell the difference. (In detail, the address of the objects in .bss would probably be different from the address if it was in the .data segment.)

- Saurabh Singhal August 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Global and static variables are initialized to zero prior program execution (if they do not have explicit initial value assigned to the like int x = 1;)

- Selmeczy, Péter August 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Since i is an unsigned global variable it goes into BSS for storage and bss initializes its every variables with '0'.
hence zero output.

- Sudheer Telugu August 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry "uninitialized"

- Sudheer Telugu August 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In BSS section stored only static variables by default initializing 0. The non-static variables don't store in BSS part! One of the differences of static and non static declarations is that static variables seen only in file where declared non static variables you can use in other files.

- Vova August 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

chesk BSS section in the below link:
"uninitialized data starts at the end of the data segment and contains all global variables and static variables that are initialized to zero or do not have explicit initialization in source code."

- sudheerjay August 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

as i is global variable default value intialized will be 0...

- sud8640 September 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

here declaration of the i is globally it assign as the satic varibe.so default value of the static variable is '0';

- santhosh reddy September 25, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More