Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 59 - 61 of 354
Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.
Question 59
Explanation
- Smalltalk
- Java
- Eiffel
- Sather
Question 60
Describe in Detail Essay▾
What is the output of the following program?
main ()
{
int i =_l_abc (10);
printf ( “%d” --i);
}
int _l_abc (int i)
{
return (i ++ );
}
Explanation
In the program
int _l_abc (int i) { return (i ++) ; } |
|
int i = _l_abc (10) ; | Here int _l_abc (int i) is a function and int i = 10 defined. |
printf ( “% d” -i) ; | Print the value if --i is i = i-1 So i = 10 - 1 = 9. The decrement happens first and then print i = 9 |
Question 61
Explanation
- In c programming language, printf () is used to print the “character, string, float, integer, octal, and hexadecimal values” onto the output screen.
- To generate a newline, we use “” in C printf () statement.
- Puts () function can be used similar to printf () .
- Function int puts (const char ⚹ str) writes a string to stdout up to but not including the null character.
- Puts in combination with sprintf can produce the “printf” . “sprintf” uses the format specifiers similar to printf but instead of directing output to stdout, it directs output to a string.
- Puts outputs a newline character to the output.
Declaration:
int puts (const char ⚹ str)
Return Value:
- str:
- This is the C string to be written.
Example of puts () :
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[15];
char str2[15];
strcpy(str1, "tutorialspoint");
strcpy(str2, "compileonline");
puts(str1);
puts(str2);
return(0);
}
OUTPUT:
tutorialspoint
compileonline