GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 422 of 453    Print  
printf() and printf as a variable
can printf be used as a variable as well as a procedure?


  
Total Answers and Comments: 3 Last Update: July 10, 2009     Asked by: chandrikakr 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Jaya_Kaja
 

printf  can be used as a variable . But once we declare a variable printf ,
standard Library function "printf"  can not be recongnized by the compiler within   the scope of the variable  (reason :local symbol might be having higher precedence ).
If at all library func is  used ,compiler  wil throw the error saying- " called object is not a function."

For eg : below  is an  error free C program :

#include <stdio.h>
int main()

{
     int printf;
     printf = 10;
  /*  printf("n My Number = %d",num);*/  /* Activating this line,causes an error */
     Display( printf);
    return 1;
}

Display(int num)
{
    printf("n My Number = %d",num);
}

Note : But in programming it is not recommended to  use the sandard symbols.



-Jayalakshmi  Kaja
 



Above answer was rated as good by the following members:
kmcanil, sourabh_t, rajani_vaddepalli15
July 14, 2008 17:06:49   #1  
janhavibend Member Since: July 2008   Contribution: 5    

RE: printf() and printf as a variable
printf can't be used as a variable name. Printf is a library function and When you are trying to use printf variable compiler will give an error like "called object 'printf' is not a function"
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
July 18, 2008 12:41:13   #2  
Jaya_Kaja Member Since: July 2008   Contribution: 3    

RE: printf() and printf as a variable

printf can be used as a variable . But once we declare a variable printf
standard Library function "printf" can not be recongnized by the compiler within the scope of the variable (reason :local symbol might be having higher precedence ).
If at all library func is used compiler wil throw the error saying- " called object is not a function."

For eg : below is an error free C program :

#include <stdio.h>
int main()

{
int printf;
printf 10;
/* printf("n My Number d" num);*/ /* Activating this line causes an error */
Display( printf);
return 1;
}

Display(int num)
{
printf("n My Number d" num);
}

Note : But in programming it is not recommended to use the sandard symbols.



-Jayalakshmi Kaja


 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 0Overall Rating: +3    
July 10, 2009 12:00:48   #3  
sarav957 Member Since: February 2008   Contribution: 2    

RE: printf() and printf as a variable

We can use printf as a variable and it is compiling GCC compiler

This is my program which is having runtime and compiled successfully without any
warning


#include<stdio.h>



int main( )

{

char printf 'a'; /*for printing use other than printf function*/

putchar(printf);

return o;

}



 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape