







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
this is a slides for Programming Fundamentals for Engineers in c languge
Typology: Slides
1 / 13
This page cannot be seen from the preview
Don't miss anything!








Al-Quds University - Faculty of Engineering - Computer Engineering Department Programming Fundamentals for Engineers 0702102 Final Exam Monday, January, 17th, 2011 Time allowed: 120 minutes Circle your section: (1) SW 8:00 – 9:20 (2) NT 9: Name: _____________________________________________ Reg #: ______________________________ Note: Before writing your C Code, provide adequate Analysis/Algorithm where applicable (mainly in Q 3 and 4). Start answering every question in a new page! Answer Quetion1 and Question 2 on this question paper & Submit with answer book! Q1) What is the exact output in each case of the following, assuming these declarations before each one? ( marks) i n t i = 2 , j , k = 0 , * v , x , * l , y , z , w = 1 0 , * m , n = 4 , o , * n P t r , * o P t r , p , q , r ; p = q = r = 2 0 ; 1 ) w h i l e ( i < = 1 5 ) { f o r ( j = 1 ; j < = 1 5 ; j + + ) i f ( j % 3 = = 0 ) k + + ; i = i + 2 ; } p r i n t f ( " \ n k = % d " , k ) ; S o l u t i o n : k = 35
Note: Decrement of 1 in integer pointer means FA120015 - 4 = FA Answer in above box is according to the assumption in question
n P t r = & n ; o = * n P t r / 3 + 1 2 ; o P t r = n P t r ; p r i n t f ( " n = % d , o = % d , * n P t r = % d , * o P t r = % d \ n " , n , o , * n P t r , * o P t r ) ; N=4, o=13, *nPtr=4, *oPtr=4 (4)
Q2) What is the output of the following programs? (12 marks) main() { char far *s1, *s2; printf (“%d%d”, sizeof(s1), sizeof (s2)); } 4 2 int x=40; main() { int x=20; printf (“\n%d”,x); } 20 Whenever there is a conflict between local and global variables – the local variable gets priority main() { int x=40; { int x = 20; printf (“\n%d”, x); } printf (“%d”, x); } 20 40 the variable that is more local gets priority incase of conflict between local variables main() { int i=4; switch (i) { default: printf (“\n Chocolate”); case 1: printf (“\n Vanilla”); break; case 2: printf (“\n Strawberry”); break; case 3: printf (“\n Then nothing”); } }
main() { inti = -3,j=2,k=0,m; m = ++j&&++i||++k; printf(“\n%d%d%d%d”,i,j,k,m); }
If the binary equivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what would be the output of the following program? main() { float a=5.375; char p; inti; p = (char)&a; for (i-0, i<=3; i++) printf (“%02x”, (unsigned char) p[i]); } 00 00 AC 40 Q3) Answer with True or False (20 marks)
Q5) a. Develop an algorithm that asks the user to enter two positive non equal numbers representing the low_end and high_end values of a range, compute and output the sum of the even numbers in the range? ( marks) b. Develop a function to swap two characters using pointers? (5 marks)