Cprintf is defined to send formatted output to the text window on the screen. And printf directs its output to the stdout. What is the difference between stdout and a text window then? Does the screen serve differently while using cprintf and printf? Please explain
128
Answer is a)128. Here we are not modifying const value. We are just assigning value to const variable.
Language and scripting language
Explain the difference between language and scripting language?
The origin of the term was similar to its meaning in "a movie script tells actors what to do": a scripting language controlled the operation of a normally-interactive program, giving it a sequence of ...
"Scripting" language *usually* implies a language thats interpreted as opposed to compiled, with lots of high-level operations for file manipulation, pattern matching, job management, etc. and geared ...
Pre and post increment operators
Why does ++i * ++i give 49 when i=5?
it increments i by 1i.e i becomes 6 in first subexpression and becomes in 7 in second subexpression.finally 42 is answer
Priority of pre increment is high so:
1. firstly ++i is executed then i=6;
2. then again ++i is executed and i=7;
3. and then the multiplication is done so i*i or 7*7 is 49.
What is the break statement used for?1. To quit the program.2. To quit the current iteration.3. To stop the current iteration and begin the next iteration.4. None of the above.
to quit the current iteration. i.e. jump out of the loop.
3. To stop the current iteration and begin the next iteration.
Can more than one main() exist in the same program??
yes, it is called recursion
Only one main main function is allowed. But you can call that main function n number of times.
Enter key carriage return or linefeed?
When we press enter to end the program and press alt+f5 to see the output again, we see that the getche() function places the cursor at the beginning of the line. So, does the enter key specify carriage return in this case. But while entering output, it works as a newline character... Please explain...
Enter key is line feed.
A program in C using void pointer
I know that this program is wrong as error is shown on compiling it. Anyone please provide a simple program using Void pointer in C. Thanks in advance :)Code
#include<stdio.h> #include<conio.h> int main() { int a=10; void *p; p=&a; clrscr(); getch(); return; }
You have to typecast void pointer to int as *(int*)p;
Code
#include<stdio.h> #include<conio.h> int main() { int a=10; void *p; p=&a; clrscr(); getch(); return 0; }
Your error is on line 9, where youve attempted to dereference a pointer to void (the expression *p). You can only dereference typed pointers. The solution you are probably looking for would be to repl...
Print number of distinct characters in a string.
How do I implement a C program that reads a string and prints a table with the number of occurrences of each character in the string. ex: rubber. R = 2, u = 1, b = 2, e = 1.
Simple, fairly brain-dead example. Assumes any input characters fall into the range [0...CHAR_MAX). "c #include #include #include int main(int argc, char **argv) { int coun...
Can you please explain the declaration of getch() function that is "int getch(void)"? i have the doubt that if its return type is int, why is the character typed from the keyboard is displayed as it is? It should be displayed in its ascii value. Also, what does void as parameter in this function stand...
In C, all the character-oriented functions (getc, fgetc, getchar, etc.) return int instead of char, mainly to support an out-of-band value for EOF (an integer expression with a negative value).
The "void" in the parameter list indicates that the function takes no parameters.
Sum of two numbers without using arithmetic operators
Ex:int a=10;int b=10;int sum=a+b;without using "+" operator calculate sum
Answered by: jintojos
Member Since May-2008 | Answered On : Jul 17th, 2008
void main()
{
int a=10,b=20;
while(b--) a++;
printf("Sum is :%d",a);
}
For two positive numbers:
int main(){
int a = 10;
int b = 10;
printf("%d",a ^ b | ((a & b)<< 1));
return 0;
}
Code
#include<stdio.h> #include<conio.h> main() { int a=20,b=10,c; clrscr(); c=a-~b-1; //it will change the sign of operator truly magic getch(); return 0; }
Is it possible to print colors with printf statements ?
include conio.h header file and textcolor(int value) function and dont forget to use cprintf statement : ex:
now hello world will be displayed in yellow colorCode
textcolor(2); cprintf("hell world");
Not directly. The printf function simply sends formatted text to the output stream. However, with some terminals, you can send control codes as part of the formatted text, and these control codes ca...
What is the output of the following code?
1) 1 2 3 4 5 6 7 8 9 2) 1 2 3 10 3) 4 5 6 7 8 9 10 4) 4 5 6 7 8 9Code
#include<stdio.h> void main() { int s=0; while(s++<10) { if(s<4 && s<9) continue; %d ",s); } }
Ans:3 s++ means-first s=0 then s=s+1.so checking the initial value of s & then increment the value of s.In this way continuing this process & print the value of s.
45678910
String abc = showdata()["hello"]; can somebody explain what is use of ["hello"] after function call?
C doesn't have a String data type, unless that supposed to be a typedef for something. Having said that, I think this is taking advantage of the fact that array indexing in C is commutative; IOW, "...
Read specified number of elements
What function will read a specified number of elements from a file?
fread() function will read a specified number of elements from a file .
its the read() function
the syntax is
int bytes = (fp, buf,1);
First argument is the source file, second argument is the address of the buffer and the third argument is the maximum number of bytes we want to read.
It returns the number of bytes actually read.
Accept an amount in rupees (indian currency ) from the user...
....And find the minimum number of notes to form that amount. the denominations are 500,100,50,20,10,5,2,1 rupee. using any loop!!
"c #include int main(){ int amount,no_hun,no_fifty,no_ten,no_five,no_two,no_one,total_notes; printf(" Enter the amount: "); scanf("%d",&amount); no_hun=amount/100; amount=amoun...
Accept two numbers from the user...
...And multiply these two numbers without using the multiplication operator! using any loop!
Code
#include<stdio.h> #include<stdlib.h> main() { int a,b,result=0; scanf("%d%d",&a,&b); while(a) { result=result+b; a--; } ",result); }
I have included the code herein for u."c //Program for Multiplication without using multiplication operator written by Er.Kunal #include #include void main() { int multiplican...
Write a program to accept 20 numbers from the user
And count how many positive and how many negative and 0 numbers were entered!! pls
Code
#include<stdio.h> main() { int a[20],i; int pos,neg,zero; pos=neg=zero=0; for(i=0;i<5;i++) { scanf("%d",&a[i]); if(a[i]>0) pos++; else if(a[i]<0) neg++; else zero++; } ",pos,neg,zero); }
Some questions answers are compiler dependent..So correct it, as in my test I observed the sizeof int is 2 bytes which was in 16bit compiler like turbo. Now world has moved to 32 bits, even 64 bits will coming near soon, so change ur test ans....
Write a function reverse which takes a strings as a parameter and prints it out in reverse.
Example:reverse (hello) prints out (olleh)
Code
#include<stdio.h> #include<string.h> void main() { int a,i; char b[100]; char s[100]="in this world let there be a name and fame to those who can"; a=strlen(s); for(i=0;i<=s;i++) { b[i]=s[a-i]; } }