SlideShare une entreprise Scribd logo
1  sur  1
Télécharger pour lire hors ligne
The Joy of
Programming
                                                                                                                                            S.G. GANESH

 How ‘C’mart Are You?
 Here's a new feature on programming puzzles in C. Check out the solutions and
 have some fun.

 Quines
 Write a program that prints the source code of that                                         For the last %c, the argument is the new line, which
 program itself (such programs are known as ‘quines’). The                                gets printed. Now you can verify the fact that the source
 solution need not be generic; it is enough that the program                              program and the output are same, character-by-character!
 written prints itself.
     Note: You should not resort to shortcuts such as file                                Find the bug
 I/O operations to open the source file and print the                                     The following program intends to print a paragraph text,
 contents.                                                                                but the program didn’t work as expected. Can you find out
              Here is a well-known and clever solution:                                   why?
GUEST COLUMN




               char*f=”char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c”;main()               #include <stdio.h>

               {printf(f,34,f,34,10);}
                                                                                           int main() {

                   The ASCII values for double-quotes and new-                                        printf(“C’s free-formatted nature and features n”

               line characters are 34 and 10. The basic idea                                          “like preprocessor can make the debugging n”,

               behind this program is to have a formatting string                                     “process complex; typos can lead to nasty bugs, n”

               and print it twice with formatting characters.                                         “not being caught at compile time. Though n”
                                                                                                      “its frustrating at times, the power and n”

               To understand the program, start from the printf in                                    “flexibility that C provides is also a source n”

               main(). It has a formatting string f (which is                                         “of joy in the hands of an expert C programmer.n”);

               “char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c”).                           }


                   The printf routine takes ‘f’ as the argument                               Two continuous string literals separated by white space
               and starts printing the characters. While printing                         characters are concatenated by the compiler and treated
               the characters, it encounters the double-quote                             as a single string literal (known as ‘stringization’
               character and prints the “.                                                operation).
                   After that it sees %s in the formatting string                             The programmer expected the whole text to get
               for which the value of f is to be printed. So the                          printed as the list of string literals provided as the
               output looks like:                                                         argument to printf would get concatenated. However,
                                                                                          there is a comma (possibly a typo) at the end of the string
   char*f=”char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c                                  “like preprocessor can make the debugging n”. So only the
                                                                                          first part of the printf gets printed!
   Now, it again sees a %c and it prints a “:


   char*f=”char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c”                                  By: S.G. Ganesh is an engineer in Hewlett-Packard’s C++
                                                                                           compiler team. He has authored a book “Deep C” (ISBN 81-
    Then it prints the rest of the string till it encounters                               7656-501-6). He is also a member of ANSI/ISO C++
 another %c:                                                                               Standardization committee (JTC1/SC22/WG21)
                                                                                           representing HP. He has a master’s degree in computer
   char*f=”char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c”;main(){printf(f,34,f,34,10);}    applications from PSG College of Technology, Coimbatore.



                                                                                               www.linuxforu.com   |   LINUX FOR YOU   |   JANUARY 2007    119


                                                                                  CMYK

Contenu connexe

Tendances

miniLesson on the printf() function
miniLesson on the printf() functionminiLesson on the printf() function
miniLesson on the printf() functionChristine Wolfe
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshopneosphere
 
TDD in C - Recently Used List Kata
TDD in C - Recently Used List KataTDD in C - Recently Used List Kata
TDD in C - Recently Used List KataOlve Maudal
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Insecure coding in C (and C++)
Insecure coding in C (and C++)Insecure coding in C (and C++)
Insecure coding in C (and C++)Olve Maudal
 
20 C programs
20 C programs20 C programs
20 C programsnavjoth
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Surprise! It's PHP :) (unabridged)
Surprise! It's PHP :) (unabridged)Surprise! It's PHP :) (unabridged)
Surprise! It's PHP :) (unabridged)Sharon Levy
 

Tendances (19)

C programming
C programming C programming
C programming
 
miniLesson on the printf() function
miniLesson on the printf() functionminiLesson on the printf() function
miniLesson on the printf() function
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
2 data and c
2 data and c2 data and c
2 data and c
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
TDD in C - Recently Used List Kata
TDD in C - Recently Used List KataTDD in C - Recently Used List Kata
TDD in C - Recently Used List Kata
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Insecure coding in C (and C++)
Insecure coding in C (and C++)Insecure coding in C (and C++)
Insecure coding in C (and C++)
 
CP Handout#6
CP Handout#6CP Handout#6
CP Handout#6
 
20 C programs
20 C programs20 C programs
20 C programs
 
First c program
First c programFirst c program
First c program
 
1
11
1
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Session 5-exersice
Session 5-exersiceSession 5-exersice
Session 5-exersice
 
C programming language
C programming languageC programming language
C programming language
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Surprise! It's PHP :) (unabridged)
Surprise! It's PHP :) (unabridged)Surprise! It's PHP :) (unabridged)
Surprise! It's PHP :) (unabridged)
 
Semaphore
SemaphoreSemaphore
Semaphore
 

En vedette (16)

Youth Flash, April 2012
Youth Flash, April 2012Youth Flash, April 2012
Youth Flash, April 2012
 
Bylaws
BylawsBylaws
Bylaws
 
16 Jop April 08
16 Jop April 0816 Jop April 08
16 Jop April 08
 
2007 - Follow-up to the World Programme of Action for Youth to the Year 2000 ...
2007 - Follow-up to the World Programme of Action for Youth to the Year 2000 ...2007 - Follow-up to the World Programme of Action for Youth to the Year 2000 ...
2007 - Follow-up to the World Programme of Action for Youth to the Year 2000 ...
 
Opdracht 1
Opdracht 1Opdracht 1
Opdracht 1
 
USING PREDICTIONS TO POWER CUSTOMER SUCCESS
USING PREDICTIONS TO POWER CUSTOMER SUCCESSUSING PREDICTIONS TO POWER CUSTOMER SUCCESS
USING PREDICTIONS TO POWER CUSTOMER SUCCESS
 
2011 - Commission for Social Development, 49th Session Resolution on Policies...
2011 - Commission for Social Development, 49th Session Resolution on Policies...2011 - Commission for Social Development, 49th Session Resolution on Policies...
2011 - Commission for Social Development, 49th Session Resolution on Policies...
 
1999 - General Assembly resolution on Policies and Programmes Involving Youth...
1999 - General Assembly resolution on Policies and Programmes Involving Youth...1999 - General Assembly resolution on Policies and Programmes Involving Youth...
1999 - General Assembly resolution on Policies and Programmes Involving Youth...
 
Planeamiento Bimestral Xii
Planeamiento Bimestral XiiPlaneamiento Bimestral Xii
Planeamiento Bimestral Xii
 
05 Jo P May 07
05 Jo P May 0705 Jo P May 07
05 Jo P May 07
 
Roset 1
Roset 1Roset 1
Roset 1
 
Examen R 2
Examen R 2Examen R 2
Examen R 2
 
Sabia Usted Que
Sabia Usted QueSabia Usted Que
Sabia Usted Que
 
Saint patrick's day
Saint patrick's daySaint patrick's day
Saint patrick's day
 
Presentazione
PresentazionePresentazione
Presentazione
 
Salutacion Dia Del Periodista 2
Salutacion Dia Del Periodista 2Salutacion Dia Del Periodista 2
Salutacion Dia Del Periodista 2
 

Similaire à 01 Jo P Jan 07

COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxCOMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxdonnajames55
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184Sumit Saini
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
Deep C Programming
Deep C ProgrammingDeep C Programming
Deep C ProgrammingWang Hao Lee
 
1.1 programming fundamentals
1.1 programming fundamentals1.1 programming fundamentals
1.1 programming fundamentalsJawad Khan
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comAkanchha Agrawal
 
Test flawfinder. This program wont compile or run; thats not
 Test flawfinder.  This program wont compile or run; thats not Test flawfinder.  This program wont compile or run; thats not
Test flawfinder. This program wont compile or run; thats notMoseStaton39
 

Similaire à 01 Jo P Jan 07 (20)

COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docxCOMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
COMP 2103X1 Assignment 2Due Thursday, January 26 by 700 PM.docx
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
C programming
C programmingC programming
C programming
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Deep C Programming
Deep C ProgrammingDeep C Programming
Deep C Programming
 
The basics of c programming
The basics of c programmingThe basics of c programming
The basics of c programming
 
1.1 programming fundamentals
1.1 programming fundamentals1.1 programming fundamentals
1.1 programming fundamentals
 
Lab 2
Lab 2Lab 2
Lab 2
 
14 Jo P Feb 08
14 Jo P Feb 0814 Jo P Feb 08
14 Jo P Feb 08
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
25 Jo P Jan 09
25 Jo P Jan 0925 Jo P Jan 09
25 Jo P Jan 09
 
03 Jo P Mar 07
03 Jo P Mar 0703 Jo P Mar 07
03 Jo P Mar 07
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
2 debugging-c
2 debugging-c2 debugging-c
2 debugging-c
 
10 Jo P Oct 07
10 Jo P Oct 0710 Jo P Oct 07
10 Jo P Oct 07
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
comp2
comp2comp2
comp2
 
Test flawfinder. This program wont compile or run; thats not
 Test flawfinder.  This program wont compile or run; thats not Test flawfinder.  This program wont compile or run; thats not
Test flawfinder. This program wont compile or run; thats not
 

Plus de Ganesh Samarthyam

Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeGanesh Samarthyam
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”Ganesh Samarthyam
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGanesh Samarthyam
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeGanesh Samarthyam
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationGanesh Samarthyam
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterGanesh Samarthyam
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Ganesh Samarthyam
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckGanesh Samarthyam
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageGanesh Samarthyam
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Ganesh Samarthyam
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz QuestionsGanesh Samarthyam
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz QuestionsGanesh Samarthyam
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizGanesh Samarthyam
 

Plus de Ganesh Samarthyam (20)

Wonders of the Sea
Wonders of the SeaWonders of the Sea
Wonders of the Sea
 
Animals - for kids
Animals - for kids Animals - for kids
Animals - for kids
 
Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in Practice
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't Enough
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief Presentation
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - Poster
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship Deck
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz Questions
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quiz
 

Dernier

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Dernier (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

01 Jo P Jan 07

  • 1. The Joy of Programming S.G. GANESH How ‘C’mart Are You? Here's a new feature on programming puzzles in C. Check out the solutions and have some fun. Quines Write a program that prints the source code of that For the last %c, the argument is the new line, which program itself (such programs are known as ‘quines’). The gets printed. Now you can verify the fact that the source solution need not be generic; it is enough that the program program and the output are same, character-by-character! written prints itself. Note: You should not resort to shortcuts such as file Find the bug I/O operations to open the source file and print the The following program intends to print a paragraph text, contents. but the program didn’t work as expected. Can you find out Here is a well-known and clever solution: why? GUEST COLUMN char*f=”char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c”;main() #include <stdio.h> {printf(f,34,f,34,10);} int main() { The ASCII values for double-quotes and new- printf(“C’s free-formatted nature and features n” line characters are 34 and 10. The basic idea “like preprocessor can make the debugging n”, behind this program is to have a formatting string “process complex; typos can lead to nasty bugs, n” and print it twice with formatting characters. “not being caught at compile time. Though n” “its frustrating at times, the power and n” To understand the program, start from the printf in “flexibility that C provides is also a source n” main(). It has a formatting string f (which is “of joy in the hands of an expert C programmer.n”); “char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c”). } The printf routine takes ‘f’ as the argument Two continuous string literals separated by white space and starts printing the characters. While printing characters are concatenated by the compiler and treated the characters, it encounters the double-quote as a single string literal (known as ‘stringization’ character and prints the “. operation). After that it sees %s in the formatting string The programmer expected the whole text to get for which the value of f is to be printed. So the printed as the list of string literals provided as the output looks like: argument to printf would get concatenated. However, there is a comma (possibly a typo) at the end of the string char*f=”char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c “like preprocessor can make the debugging n”. So only the first part of the printf gets printed! Now, it again sees a %c and it prints a “: char*f=”char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c” By: S.G. Ganesh is an engineer in Hewlett-Packard’s C++ compiler team. He has authored a book “Deep C” (ISBN 81- Then it prints the rest of the string till it encounters 7656-501-6). He is also a member of ANSI/ISO C++ another %c: Standardization committee (JTC1/SC22/WG21) representing HP. He has a master’s degree in computer char*f=”char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c”;main(){printf(f,34,f,34,10);} applications from PSG College of Technology, Coimbatore. www.linuxforu.com | LINUX FOR YOU | JANUARY 2007 119 CMYK