Tutorial-1 (Introduction To C Programming / Operators / Input-Output)
This document provides 10 questions about C programming concepts like operators, input-output, precedence and associativity order of operators. For each question, it provides the code snippet and hints to find the output. The key concepts covered are operators like logical NOT(!), relational(>, <, <=, >=), arithmetic(+, -, *, /), precedence and associativity order of operators, escape sequences, input-output using scanf and printf functions.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
30 views
Tutorial-1 (Introduction To C Programming / Operators / Input-Output)
This document provides 10 questions about C programming concepts like operators, input-output, precedence and associativity order of operators. For each question, it provides the code snippet and hints to find the output. The key concepts covered are operators like logical NOT(!), relational(>, <, <=, >=), arithmetic(+, -, *, /), precedence and associativity order of operators, escape sequences, input-output using scanf and printf functions.
Tutorial-1 (Introduction to C Programming / Operators / Input-Output)
1. Find the output of following program. #include<stdio.h> int main() { int i = 10; printf(“%d %d”,i++/++i, i); return 0; } Hint:- The order of execution is: i++/++i = i++/(++i=i+1=10+1=11) = 11/11 = 1; i = i++ = i+1 = 11+1 =12. Output: 1 12 (Note that outcome is machine dependent)
2. Find the output of the following program.
#include<stdio.h> int main() { int i=1; printf(“%d %d”,i+++i, i ); return 0; } Hint:- The order of execution is: i+++i = i+i = 1+1 =2; i = i++ = i+1 = 1+1 =2.
Output: 2 2 (Note that outcome is machine dependent )
3. Find the output of the following program.
#include<stdio.h> int main() { int i=10, b; b=i+++--i; printf(“%d %d”, b,i); return 0; } Hint:- The order of execution is: b=i+++--i = i+++(--i = i-1 = 9) = (i+I = 9+9) = 18; i = i++ = i+1 = 9+1 = 10. Output: 18 10 (Note that outcome is machine dependent) 4. Predict the output of the questions given below. #include<stdio.h> int main() { int i = 10; printf(“%d\n%d”,printf(“IIT ISM\n”,i)); return 0; } Hint :- printf returns the number of characters printed on output screen. Output: IIT ISM 8 10 5. Print the output of the program given below #include<stdio.h> int main() { printf(“Hello\”IIT\”ISM\n”); printf(“\’\\\\\’”); printf(“\n\’a\?b\’c”); return 0; } Hint :- Use the escape sequence concept for backslash, double quote, single quote, and question mark. Output: Hello”IIT”ISM ’\\’ ’a?b’c
6. What is the output of the program given below?
#include<stdio.h> int main() { int _int; float _float; scanf(“%d\n”,scanf(“%d %f”, &_int, &_float)); float a, b; a= float(_int); b= a*2/_float; printf(“%.2f\n%.4f”,a,b); return 0; } Hint:- scanf returns the number of inputs taken from user. Input: 25, 12.5 Output: 2, 25.00, 4.0000 7. Find the output of the following program #include<stdio.h> int main() { int a=0,b=10,c=20,x,y; x=(!(a<b>c)); printf(“%d ”,x); y=a>10<=20 printf(“%d”,y); return 0; } Hint: Use the precedence and associativity order. Output: 1 1
8. Find the output of following program.
#include<stdio.h> int main() { int a=0,b=5,x; x=(!(!a) && !a); printf(“%d”,x); return 0; } Hint:- Logical NOT (!) operator precedence is higher than Logical AND (&&). Output: 0
9. Find the output of the following program
#include<stdio.h> int main() { int a=100, b=200, c=300,x,y,z; x= !a>500; y= b<=300; z= 50<a<200; printf(“%d %d %d”,x,y,z); return 0; } Hint:-Precedence of Logical NOT (!) operator is higher than Relational greater than (>) operator. Output: 0 1 1 10. Find the output of the following program. #include<stdio.h> int main() { int i=0, k=0, p=2, m, j=-1; m=i++ &&j++ && k++ || p++; printf(“%d %d %d %d”, i, j, k, p, m); return 0; } Hint:-Use the precedence order of Logical AND (&&) and Logical OR (||). In Logical AND operation, if any operand value is false then the further operand will not be checked and the final value is taken as false. This is also known as short circuiting of logical AND.