Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9165837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:00:03+00:00 2026-06-17T15:00:03+00:00

I am trying to do a program where the function is pointed by a

  • 0

I am trying to do a program where the function is pointed by a pointer. It goes as follows:-

This is the first program which uses “void” return type.

#include<stdio.h>
#include<conio.h>
void CharPrint(char *ptr);
main()
{
    char *str="Hello World";
    void (*ptr1)(char *ptr);
    ptr1=CharPrint;
    if((*ptr1)(str))
        printf("Done");
    return 0;
}
void CharPrint(char *ptr)
{
    printf("%s\n",ptr);
}

It throws many errors. They are:-

enter image description here

The second program is as follows:-

#include<stdio.h>
#include<conio.h>
int CharPrint(char *ptr);
main()
{
    char *str="Hello World";
    int (*ptr1)(char *ptr);
    ptr1=CharPrint;
    if((*ptr1)(str))
        printf("Done");
    return 0;
}
int CharPrint(char *ptr)
{
    printf("%s\n",ptr);
    return 0;
}

This program runs without any hiccup.

The output is:-

enter image description here

My problem is that in the first output, why is it showing ” Not an allowed type in function main ” on line 9. The other lines are also arising doubts but this line is bugging me the most. Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:00:06+00:00Added an answer on June 17, 2026 at 3:00 pm
    void (*ptr1)(char *ptr);
    ptr1=CharPrint;
    if((*ptr1)(str))
        printf("Done");
    

    What is the if testing if the return value is void? Just change the last two lines to:

    ((*ptr1)(str));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to exploit my format string bug, which lies in this program: #include
So, I'm trying to write a function which return a pointer to an ADT,
Based on this question which was closed rather quickly: Trying to create a program
I'm trying to write a program which calls a library function ( http://www.diku.dk/hjemmesider/ansatte/pisinger/3dbpp.c )
Here is my program which reverses a string. I am trying to use function
I'm trying, for educational purposes, to run a program which uses a buffer overflow
I am trying to understand the disassembled version of this program: #include <stdio.h> int
This is a program trying to make a linked list. #include <iostream> using namespace
In my program I am trying to resize array using malloc function. #include <stdio.h>
I am trying tot pass argv from the main function of my program to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.