C programming Basic 1



(1). #include<stdio.h>
int main()
{
printf("The single quote \' is this ");
}


(2). #include<stdio.h>
int main()
{
printf("The single quote ' is this ");
}

Questions

(a)same output so why we take \' as escape sequence . It does not do anything special??



(b) Why did these characters call "escape sequences" . ?
Help plzz
Last edited on
It does not do anything special??
Not in this context. But you can use single quotes like here: char ch = '\'';

Why did these characters call "escape sequences" . ?
Just a wording. Look at this:
http://en.wikipedia.org/wiki/Escape_sequence
Thanks :)
Try these two instead:

 
printf("I want to print a " character"); 


 
printf("I want to print a \" character");


Note, even the syntax highlighting on this site shows the difference.
Last edited on
#include<stdio.h>
void main()
{
printf("%d",printf("Computer"));
}



has a output = computer 8

Why ? please explain someone.
:confused:
Last edited on
The general syntax of that looks off.

It's like you're trying to print a signed decimal integer variable, then trying to call printf again to print a string literal.

What exactly were you trying to do?

Were you trying to do this?:
 
printf("%s", "Computer");


I think that what you're effectively doing in your example is printing the value returned by the printf function. It returns 8 because printf will return the number of characters printed.
Last edited on
It outputs 8, because your code is currently printing the return value of the printf function call.

1
2
3
4
5
#include<stdio.h>
void main()
{
printf("%s","Computer");
}

This way your programm will output the string. %d tells the printf function that you want to output an integer, %s is a placeholder for string parameters.
ohh I got it . Every function returns a value . And printf function returns the value of the number of characters in the string which he has printed .. :)
Every function returns a value .

Except the ones marked "void" at the start of the prototype :)
Last edited on
hmm newbie me :(
hmm newbie me :(


No shame in not knowing; only in feigning knowledge and in refusing to learn :)
Why dont we use '&' in the case of strings in function scanf ??

e.g. :-


scanf("%s",date);

here date is a character arraymeans string.


Plz help

Last edited on
Maybe because date is a pointer?

Seriously, stop using scanf.
I am learning C . So it will come into the concepts . I have to learn scanf also :( :( .
Topic archived. No new replies allowed.