Sona Programming Club
Activities:
1. Train students to solve programming problems of varying difficulty levels given in websites like www.codechef.com, www.spoj.pl, etc.
2. Meet weekly once and discuss about various algorithms.
3. Periodically suggest books to learn various programming languages.
4. Frequently conduct innovative events related to programming and motivate students to develop programming skills.
5. Regularly update the new standards and changes of the programming languages.
Dear friends,
SProC is back again to ignite your programming skills !
Come, Code, Compete.!!
www.sproc.tk
Sona Programming Club Sona Programming Club
Date of post: 19.4.12
Category: Questions
Number: 12
Post content:
Sona Programming Club ( SProC )
"Let us C beyond the C"
Answers for the questions asked on 12.4.12:
1. Question:
main() { int a = '1', b = '11' ; printf ( "%d %d", a, b ) ; }
Answer: 49 12593
Explanation: The value is stored as binary in consequent memory.
'1' is stored as 0011 0001 whose integer equivalent is 49. Similarly, '11' is stored as 0011 0001 0011 0001 whose integer value is 12593.
2. Question:
main() { int y = 7 ; if ( !!y ) printf ( "%d", !y ) ; else printf ( "%d", y ) ; }
Answer: 0
Explanation: !y makes non-zero ( 7 ) value as 0 and !!y makes zero value as 1 ( True )
3. Question:
main () { int i = 1 ; j = -1 ; if ( printf ( "%d", i ) > printf ( "%d", j ) ) printf ( "%d", i ) ; else printf ( "%d", j ) ; }
Answer: 1-1-1
Explanation: printf returns the number of characters displayed
4. Question:
main() { int i = -1 ; if ( i ++ ) printf ( "True" ) ; else printf ( "False" ) ; }
Answer: True
Explanation:
i ++ is post increment and -1 is also true
5. Question:
main() { int a = 12 ; printf ( "%p", a ) ; }
Answers: 0xc for gcc compiler ; 000C for Turbo C compiler
Explanation: The hexadecimal equivalent is printed for %p.
Date of post: 12.4.12
Category: Questions
Number: 11
Post content:
Sona Programming Club ( SProC )
"Let us C beyond the C"
Answers for questions asked on 5th April, 2012:
1.
Question:
Predict the output
main() { char str[] = "Sona\0Programming\0Club" ; printf ( "%s %s %s\n", str + 17, str + 5, str ) ; }
Answer:
Club Programming Sona
Explanation:
The values 17 and 5 are added to the base address of the string 'str' and the behaviour of printf is it prints till a null character is encountered. Though only "Sona" is stored in str, "Programming" and "Club" are stored in subsequent memory locations.
2.
Question:
What is the output?
main() { int i = 0 ; ! i && printf ( "Text" ) ; }
Answer:
Text
Explanation:
The '!' operator converts 0 to 1, which is true and the printf is evaluated as the behaviour of '&&' is to check the second instruction only if the first one is true.
3.
Question:
What would be the output?
main () { printf ( "What\0are you doing ? " ) ; }
Answer:
What
Explanation:
The behaviour of printf is to print characters only till it reaches a \0 ( null ) character.
4.
Question:
Predict the output
main() { printf ( "Information" ) || printf ( "Technology" ) ; }
Answer:
Information
Explanation:
Since the first printf returns 11 ( number of characters printed ), the first expression evaluates to true and since the '||' operator is used, it does not check the second expression ( second printf ).
5.
Question:
Find the output
main() { printf ( "%d", printf ( "2+" ) + printf ( "2=" ) ) ; }
Answer:
2+2=4
Explanation:
Because of the ex*****on order of the printf statements.
Questions to be answered on or before 18th April, 2012:
Predict the output [2 marks] *
main() { int m = 21000 ; float n = 1.2e100 ; printf ( "%d %d", m, n ) ; }
13392 0
21000 0
13392 1.2e100
21000 1.2e100
What is the output? [2 marks] *
main() { int j ; for ( j = 0 ; j ++
Date of post: 16.02.2012
Category: Questions ( 3rd year )
Question paper number: 1a
Post content:
SONA PROGRAMMING CLUB-QUESTIONS FOR 3RD YR:
1. Look at the sample program and predict the output
void main()
{
int const * p=5;
printf("%d",++(*p));
}
Answer:
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
2. Look at the sample program and predict the output
main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer:
mmmm
aaaa
nnnn
Explanation:
s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the case of C it is same as s[i].
3. Look at the sample program and predict the output
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
Answer:
I hate U
Explanation:
For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.
4. Look at the sample program and predict the output
main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j
Click here to claim your Sponsored Listing.
Category
Contact the school
Website
Address
Salem
636005