Assignment-5 (Strings, Structures & Unions) : - Strings
Assignment-5 (Strings, Structures & Unions) : - Strings
C&DS
Can a function return structure variable?Any better alternatives to this if it is possible or not. Create an anonymous structure, create some variables from this (with & without typedef) Create a nested structure, access members of inner structure from outer one. Bit fields
Unions: Try the following code union A { int x; int y; char ch; }; union A a1; a1.x=0x10; a1.y=0x1121; print a1.x, a1.ch Calculate size of union , offset of members Convert ip address between dotted decimal format, 32 bit format using unions Anonymous unions, usage of typedef Nesting of structures, unions Union inside a structure structure inside an union etc. Miscellaneous:Precision problems Compare some int, float, double expressions, if getting precision problems rectify using the condition fabs(exp1 exp2) < 1e-5 eg:- int x = 2; float y = sqrt(4); float z=sqrt(0.1225); z==0.35 etc. Check correctness of comparisions like x==y , Buffered I/O operations int a,b,c; CDAC ACTS, Pune 3
C&DS printf(enter two no.s\n); scanf(%d%d,&,&b); //but here give input of 3 no.s separated by space. printf(ente ranother number\n); scanf(%d,&c); printf(%d,%d,%d\n,a,b,c);
What do you observer, if any prob fix it using %d while reading variable c (or) use __fpurge before reading c char c1,c2; printf(enter any character\n); scanf(%c,&c1); //you may use getchar(c1); here scanf(%c,&c2); printf(c1=%d,c2=%d\n,c1,c2); fix any prob using a space before %c or using __fpurge int x,y; for(int i=1;i<=5;i++) { printf(i=%d,i); //dont use \n at end of printf y=1/(x-5); } What do you observer when you run above code. Try the same using \n at the end of printf or by using fflush after printf