{"id":1151,"date":"2016-06-24T07:03:34","date_gmt":"2016-06-24T07:03:34","guid":{"rendered":"http:\/\/tutorialsclass.com\/?p=1151"},"modified":"2020-06-18T07:02:47","modified_gmt":"2020-06-18T07:02:47","slug":"c-printf-scanf","status":"publish","type":"post","link":"https:\/\/tutorialsclass.com\/c-printf-scanf\/","title":{"rendered":"C printf and scanf"},"content":{"rendered":"\n<p>The&nbsp;<code>printf()<\/code>&nbsp;function is used to display output and the&nbsp;<code>scanf()<\/code>&nbsp;function is used to take input from users.<\/p>\n\n\n\n<p>The&nbsp;<code>printf()<\/code>&nbsp;and&nbsp;<code>scanf()<\/code>&nbsp;functions are commonly used functions in C Language. These functions are inbuilt library functions in header files of C programming.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">printf() Function<\/h3>\n\n\n\n<p>In C Programming language, the&nbsp;<code>printf()<\/code>&nbsp;function is used for output.<\/p>\n\n\n\n<p><code>printf()<\/code> function can take any number of arguments. First argument must be enclosed within the double quotes&nbsp;&#8220;hello&#8221;&nbsp;and every other argument should be separated by comma ( , ) within the double quotes.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Important points about printf():<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li><code>printf()<\/code>&nbsp;function is defined in&nbsp;<code>stdio.h<\/code>&nbsp;header file. By using this function, we can print the data or user-defined message on monitor (also called the console).<\/li><li><code>printf()<\/code>&nbsp;can print a different kind of data format on the output string.<\/li><li>To print on a new line on the screen, we use \u201c\\n\u201d in&nbsp;<code>printf()<\/code>&nbsp;statement.<\/li><\/ul>\n\n\n\n<p>C language is case sensitive programming language. For example, printf() and scanf() in lowercase letters treated are different from Printf() and Scanf(). All characters in printf() and scanf() builtin functions must be in lower case.<\/p>\n\n\n\n<p><strong>Syntax<\/strong><\/p>\n\n\n\n<p> <code>printf(\"format specifier\",argument_list);<\/code><\/p>\n\n\n\n<p>The format string for output can be&nbsp;<code>%d<\/code>&nbsp;(integer),&nbsp;<code>%c<\/code>&nbsp;(character),&nbsp;<code>%s<\/code>&nbsp;(string),&nbsp;<code>%f<\/code>&nbsp;(float)&nbsp;<code>%lf<\/code>&nbsp;(double) and&nbsp;<code>%x<\/code>&nbsp;(hexadecimal) variable.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Simple Example of printf() Function<\/h4>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include&lt;stdio.h>  \n\nint  main()\n{   \nint num = 450; \n\/\/ print number  \nprintf(\"Number is %d \\n\", num);\n\nreturn 0;\n    \n}  <\/code><\/pre>\n\n\n\n<p>Run : <a href=\"http:\/\/ideone.com\/bQ3SGW\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/ideone.com\/bQ3SGW<\/a><\/p>\n\n\n\t<div class=\"tc-browser-container\">\r\n\t\t<div class=\"top\">\r\n\t\t\t<span class=\"tc-circle\"><\/span>\r\n\t\t\t<span class=\"tc-circle\"><\/span>\r\n\t\t\t<span class=\"tc-circle\"><\/span>\r\n\t\t\t<span class=\"tc-browser-title\"> Tutorials Class - Output Window <\/span>\r\n\t\t<\/div>\r\n\t\t<div class=\"tc-browser-content\"> <p>\nNumber is 450<\/p>\n <\/div>\r\n\t<\/div>\r\n\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">scanf() Function<\/h3>\n\n\n\n<p>The&nbsp;<code>scanf()<\/code>&nbsp;function is used to read input data from the console.<\/p>\n\n\n\n<p>The scanf() function is builtin function available in the C library.&nbsp;<code>scanf()<\/code>&nbsp;function can read character, string, numeric &amp; other data from keyboard in C language.<\/p>\n\n\n\n<p><code>scanf()<\/code>&nbsp;reads formatted data from user and assign them in the variables provided the additional arguments. Additional arguments must point to variables that have the same datatype as of user input data format. <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Syntax<\/h4>\n\n\n\n<p><code>scanf(\"format specifier\",argument_list); <\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Simple Example of scanf() Function<\/h4>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include&lt;stdio.h>  \n\nint main()\n{\n \nint x;\nprintf(\"enter the number =\");\nscanf(\"%d\",&amp;x);\nprintf(\"The number is=%d\",x);\nreturn 0; \n}<\/code><\/pre>\n\n\n\n<p>Run : <a rel=\"noopener noreferrer\" href=\"http:\/\/ideone.com\/fL7mnO\" target=\"_blank\">http:\/\/ideone.com\/fL7mnO<\/a><\/p>\n\n\n\t<div class=\"tc-browser-container\">\r\n\t\t<div class=\"top\">\r\n\t\t\t<span class=\"tc-circle\"><\/span>\r\n\t\t\t<span class=\"tc-circle\"><\/span>\r\n\t\t\t<span class=\"tc-circle\"><\/span>\r\n\t\t\t<span class=\"tc-browser-title\"> Tutorials Class - Output Window <\/span>\r\n\t\t<\/div>\r\n\t\t<div class=\"tc-browser-content\"> <p>\nenter the number =10<br \/>\nThe number is=10<\/p>\n <\/div>\r\n\t<\/div>\r\n\n","protected":false},"excerpt":{"rendered":"<p>The&nbsp;printf()&nbsp;function is used to display output and the&nbsp;scanf()&nbsp;function is used to take input from users. The&nbsp;printf()&nbsp;and&nbsp;scanf()&nbsp;functions are commonly used functions in C Language. These functions are inbuilt library functions in header files&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"keywords":[],"class_list":["post-1151","post","type-post","status-publish","format-standard","hentry","category-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C printf() and scanf() functions - Tutorials Class<\/title>\n<meta name=\"description\" content=\"printf() and scanf() functions are used for input and output in C language. Learn about printf() and scanf() functions syntax with example\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorialsclass.com\/c-printf-scanf\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C printf() and scanf() functions - Tutorials Class\" \/>\n<meta property=\"og:description\" content=\"printf() and scanf() functions are used for input and output in C language. Learn about printf() and scanf() functions syntax with example\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorialsclass.com\/c-printf-scanf\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorials Class\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/tutorialsclass\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-24T07:03:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-06-18T07:02:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/07\/tutorials-class-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"600\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tutorials Class\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@TutorialsClass\" \/>\n<meta name=\"twitter:site\" content=\"@TutorialsClass\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tutorials Class\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/tutorialsclass.com\/c-printf-scanf\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/tutorialsclass.com\/c-printf-scanf\/\"},\"author\":{\"name\":\"Tutorials Class\",\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/person\/f7d4f67fc9721ef3ea91cb21aaf89e3e\"},\"headline\":\"C printf and scanf\",\"datePublished\":\"2016-06-24T07:03:34+00:00\",\"dateModified\":\"2020-06-18T07:02:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/tutorialsclass.com\/c-printf-scanf\/\"},\"wordCount\":338,\"publisher\":{\"@id\":\"https:\/\/tutorialsclass.com\/#organization\"},\"articleSection\":[\"C Tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorialsclass.com\/c-printf-scanf\/\",\"url\":\"https:\/\/tutorialsclass.com\/c-printf-scanf\/\",\"name\":\"C printf() and scanf() functions - Tutorials Class\",\"isPartOf\":{\"@id\":\"https:\/\/tutorialsclass.com\/#website\"},\"datePublished\":\"2016-06-24T07:03:34+00:00\",\"dateModified\":\"2020-06-18T07:02:47+00:00\",\"description\":\"printf() and scanf() functions are used for input and output in C language. Learn about printf() and scanf() functions syntax with example\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorialsclass.com\/c-printf-scanf\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorialsclass.com\/c-printf-scanf\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorialsclass.com\/c-printf-scanf\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorialsclass.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learn\",\"item\":\"https:\/\/tutorialsclass.com\/learn\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"C Tutorial\",\"item\":\"https:\/\/tutorialsclass.com\/learn\/c\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"C printf and scanf\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorialsclass.com\/#website\",\"url\":\"https:\/\/tutorialsclass.com\/\",\"name\":\"Tutorials Class\",\"description\":\"Online Tutorials for Beginners\",\"publisher\":{\"@id\":\"https:\/\/tutorialsclass.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorialsclass.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/tutorialsclass.com\/#organization\",\"name\":\"Tutorials Class\",\"url\":\"https:\/\/tutorialsclass.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png\",\"contentUrl\":\"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png\",\"width\":442,\"height\":94,\"caption\":\"Tutorials Class\"},\"image\":{\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/tutorialsclass\",\"https:\/\/x.com\/TutorialsClass\",\"https:\/\/in.pinterest.com\/merientinfotech\/boards\/\",\"https:\/\/www.youtube.com\/channel\/UCzbpQXlqec-bQf1_kwrTuoA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/person\/f7d4f67fc9721ef3ea91cb21aaf89e3e\",\"name\":\"Tutorials Class\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorialsclass.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/346276d8e1600eec36df1bf9adcf78bf1eabb87fc0a79250e0565a88809b8f14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/346276d8e1600eec36df1bf9adcf78bf1eabb87fc0a79250e0565a88809b8f14?s=96&d=mm&r=g\",\"caption\":\"Tutorials Class\"},\"sameAs\":[\"tcadmin\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C printf() and scanf() functions - Tutorials Class","description":"printf() and scanf() functions are used for input and output in C language. Learn about printf() and scanf() functions syntax with example","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tutorialsclass.com\/c-printf-scanf\/","og_locale":"en_US","og_type":"article","og_title":"C printf() and scanf() functions - Tutorials Class","og_description":"printf() and scanf() functions are used for input and output in C language. Learn about printf() and scanf() functions syntax with example","og_url":"https:\/\/tutorialsclass.com\/c-printf-scanf\/","og_site_name":"Tutorials Class","article_publisher":"https:\/\/www.facebook.com\/tutorialsclass","article_published_time":"2016-06-24T07:03:34+00:00","article_modified_time":"2020-06-18T07:02:47+00:00","og_image":[{"width":600,"height":600,"url":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/07\/tutorials-class-logo.png","type":"image\/png"}],"author":"Tutorials Class","twitter_card":"summary_large_image","twitter_creator":"@TutorialsClass","twitter_site":"@TutorialsClass","twitter_misc":{"Written by":"Tutorials Class","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/tutorialsclass.com\/c-printf-scanf\/#article","isPartOf":{"@id":"https:\/\/tutorialsclass.com\/c-printf-scanf\/"},"author":{"name":"Tutorials Class","@id":"https:\/\/tutorialsclass.com\/#\/schema\/person\/f7d4f67fc9721ef3ea91cb21aaf89e3e"},"headline":"C printf and scanf","datePublished":"2016-06-24T07:03:34+00:00","dateModified":"2020-06-18T07:02:47+00:00","mainEntityOfPage":{"@id":"https:\/\/tutorialsclass.com\/c-printf-scanf\/"},"wordCount":338,"publisher":{"@id":"https:\/\/tutorialsclass.com\/#organization"},"articleSection":["C Tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/tutorialsclass.com\/c-printf-scanf\/","url":"https:\/\/tutorialsclass.com\/c-printf-scanf\/","name":"C printf() and scanf() functions - Tutorials Class","isPartOf":{"@id":"https:\/\/tutorialsclass.com\/#website"},"datePublished":"2016-06-24T07:03:34+00:00","dateModified":"2020-06-18T07:02:47+00:00","description":"printf() and scanf() functions are used for input and output in C language. Learn about printf() and scanf() functions syntax with example","breadcrumb":{"@id":"https:\/\/tutorialsclass.com\/c-printf-scanf\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorialsclass.com\/c-printf-scanf\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/tutorialsclass.com\/c-printf-scanf\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorialsclass.com\/"},{"@type":"ListItem","position":2,"name":"Learn","item":"https:\/\/tutorialsclass.com\/learn\/"},{"@type":"ListItem","position":3,"name":"C Tutorial","item":"https:\/\/tutorialsclass.com\/learn\/c\/"},{"@type":"ListItem","position":4,"name":"C printf and scanf"}]},{"@type":"WebSite","@id":"https:\/\/tutorialsclass.com\/#website","url":"https:\/\/tutorialsclass.com\/","name":"Tutorials Class","description":"Online Tutorials for Beginners","publisher":{"@id":"https:\/\/tutorialsclass.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorialsclass.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/tutorialsclass.com\/#organization","name":"Tutorials Class","url":"https:\/\/tutorialsclass.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/","url":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png","contentUrl":"https:\/\/tutorialsclass.com\/wp-content\/uploads\/2020\/05\/tutorials-class-logo.png","width":442,"height":94,"caption":"Tutorials Class"},"image":{"@id":"https:\/\/tutorialsclass.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/tutorialsclass","https:\/\/x.com\/TutorialsClass","https:\/\/in.pinterest.com\/merientinfotech\/boards\/","https:\/\/www.youtube.com\/channel\/UCzbpQXlqec-bQf1_kwrTuoA"]},{"@type":"Person","@id":"https:\/\/tutorialsclass.com\/#\/schema\/person\/f7d4f67fc9721ef3ea91cb21aaf89e3e","name":"Tutorials Class","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorialsclass.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/346276d8e1600eec36df1bf9adcf78bf1eabb87fc0a79250e0565a88809b8f14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346276d8e1600eec36df1bf9adcf78bf1eabb87fc0a79250e0565a88809b8f14?s=96&d=mm&r=g","caption":"Tutorials Class"},"sameAs":["tcadmin"]}]}},"_links":{"self":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/posts\/1151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/comments?post=1151"}],"version-history":[{"count":7,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/posts\/1151\/revisions"}],"predecessor-version":[{"id":6375,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/posts\/1151\/revisions\/6375"}],"wp:attachment":[{"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/media?parent=1151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/categories?post=1151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/tags?post=1151"},{"taxonomy":"keywords","embeddable":true,"href":"https:\/\/tutorialsclass.com\/wp-json\/wp\/v2\/keywords?post=1151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}