Lecture40 - Tobediscussedtoday 1 Variable Storage classes...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Computer Programming I TA C162 . 21 Apr 2006 To be discussed today…. . 1. Variable Storage classes in C Static variables Register Variables 2. Multi function programming examples
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Computer Programming I TA C162 . 21 Apr 2006 Static Storage Class Storage -- Memory Default initial value – Zero Scope – Local to the block Life time – Value of the variable persist between different function calls Use: 1. Counting the function calls 2. In recursive functions
Background image of page 2
3 Computer Programming I TA C162 . 21 Apr 2006 How Static Variables Work? Example: 1 void fcall_count(void) { static int count = 0; count++; printf(“count = %d”,count); } void main() { int k; for(k = 1; k<10; k++) fcall_count(); } Output??? If count is not a static variable then???
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Computer Programming I TA C162 . 21 Apr 2006 Example: 2 static int fun(int value) { static int sum; sum += value; return sum; } void main() { int i,n = 10; for(i = 1; i<n--; i++) fun(i*2); printf(“%d”,fun(0)); } What is the output???
Background image of page 4
5 Computer Programming I TA C162 . 21 Apr 2006 Register Variables A variable can be kept directly in one of the machine’s registers. Register access is faster than memory access. Keeping frequently accessed variables in registers give faster execution. How to declare:
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/14/2010 for the course CS SS ZG653 taught by Professor Shanta during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 16

Lecture40 - Tobediscussedtoday 1 Variable Storage classes...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online