/ * * Author: M.J Leslie. * Purpose: To demonstrate the 'static' storage class */ void func1(void); static count=10; /* Global variable - static is the default */ main() { while (count--) func1(); } /***************************************************************************/ void func1(void) { /* 'thingy' is local to 'func1' - it is * only initalised at run time. Its value * is NOT reset on every invocation of * 'func1' */ static thingy=5; thingy++; printf(" thingy is %d and count is %d\n", thingy, count); } /************************************************************************** Program )/P looks like this: thingy is 6 and count is 9 thingy is 7 and count is 8 thingy is 8 and count is 7 thingy is 9 and count is 6 thingy is 10 and count is 5 thingy is 11 and count is 4 thingy is 12 and count is 3 thingy is 13 and count is 2 thingy is 14 and count is 1 thingy is 15 and count is 0 **************************************************************************/
file: /Techref/language/ccpp/cref/EXAMPLES/static.c, 1KB, , updated: 1997/4/21 09:52, local time: 2024/8/14 22:26,
18.223.213.114:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://piclist.com/Techref/language/ccpp/cref/EXAMPLES/static.c"> language ccpp cref EXAMPLES static</A> |
Did you find what you needed? |
![]() o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
Welcome to piclist.com! |
.