Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

printf()

Posted on 2000-04-18
2
449 Views
Last Modified: 2013-12-14

Hi,

What is printf()? If it is a function how it will work for different parameters in c?

bye
basavaraj
0
Comment
Question by:cbasavaraj
2 Comments
 

Accepted Solution

by:
JollyJumper earned 10 total points
ID: 2728095
printf() is a function that prints formatted text to the console. It works like
printf("Hello World for the %d time",5);
%d will be replaced with "5" and the string will be printed to stdout.
for strings try %s and for floats %f
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2728123

int printf(const char *format[, argument, ...]);

It's a function, rather special as it accepts a variable number of arguments, the only required parameter is the format string. This format stringr contains information about the optional arguments. Some examples:

printf("Hello World"); // no extra args, just a plain string

char* hello = "Hello World";
printf("%s", hello);

Now the fomat string contains a format specifyer, %s, which tells the function there is a string as extra argument. You can also mix:

char* world ="World";
printf("Hello %s", world);

There are many, many specifyers and format options, you should check your compilers documentation.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Compile GLUT with Visual Studio 2015 1 174
C++ question 3 70
eclipse formatting 6 106
draw a Christmas tree by using a nested loop? 26 77
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question