IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Strings - Discussion

@ : Home > C Programming > Strings > Find Output of Program - Discussion

Read more:

"We cannot solve our problems with the same thinking we used when we created them."
- Albert Einstein
2. 

What will be the output of the program ?

#include<stdio.h>

int main()
{
    char p[] = "%d\n";
    p[1] = 'c';
    printf(p, 65);
    return 0;
}

[A]. A[B]. a
[C]. c[D]. 65

Answer: Option E

Explanation:

Step 1: char p[] = "%d\n"; The variable p is declared as an array of characters and initialized with string "%d".

Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array p becomes "%c".

Step 3: printf(p, 65); becomes printf("%c", 65);

Therefore it prints the ASCII value of 65. The output is 'A'.


Rishi said: (Tue, May 29, 2012 03:54:40 PM)    
 
How p becomes %c in the last printf statement?

John said: (Mon, Nov 12, 2012 05:38:38 PM)    
 
@Rishi.

char p[] is an array that having each array value.
p[0]=%
p[1]=d
p[2]=\
p[3]=n
then p[1]=d=c and printf("%d\n",65);
printf will change to printf("%c\n",65);
Now printf can print only character value(as of %c) finally print ASCII value of 65=A.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!