Thread: Some syntactical question on C language

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    135

    Some syntactical question on C language

    Hey everyone,
    I am tasked with some algorithmic problems in C as we as quizzes regarding the syntax of C.

    There are three questions I don't understand.
    1 - I was sure it's true because *void is like a generic pointer so we would point to any type of pointer with that.
    But I chose True and it's marked as a wrong solution - why?

    2-3. I didn't understand at all the syntax of these statements, a lot of braces of two kinds, a lot of de-references... I don't understand what's the role of each.
    Can someone explain these statements?

    1. In C language, it is always correct to use a variable of type void* to point to a pointer to a function.
    True/False

    2.
    Choose the correct description for the following statement: char (* ( *f())[])();

    Select one:
    declaration of a pointer named f to a function which receives no parameters and returns an array of pointers to functions that receive no parameters and return a char
    declaration of a pointer named f to an array of pointers to functions with no arguments returning a char
    declaration of the function f which receives no parameters and returns a pointer to an array of pointers to functions that receive no parameters and return a char
    declaration of a pointer named f to an array of functions with no arguments returning a char pointer
    Incorrect statement
    declaration of the function f which returns a pointer to an array of pointers to functions that return a char
    declaration of a pointer named f to an array of functions with no arguments returning a char

    3. Choose the correct description for the following statement: void(*f)(int, void(*)());

    Select one:
    f is a pointer to a function which returns nothing and receives as its parameters an integer and a pointer to a function which receives nothing and returns a void pointer
    Incorrect statement
    f is a function which returns a void pointer and receives as its parameters an integer and a pointer to a function which receives nothing and returns a void pointer
    f is a pointer to a function which returns a void pointer and receives as its parameters an integer and a pointer to a function which receives nothing and returns a void pointer
    f is a pointer to a function which returns nothing and receives as its parameters an integer and a pointer to a function which receives nothing and returns nothing


  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    952
    You need a different book if it's asking you questions without teaching you what you need to know to answer them.
    If you want the truth to stand clear before you, never be for or against. - Sent-ts'an

  3. #3
    Registered User
    Join Date
    Nov 2019
    Posts
    135
    Quote Originally Posted by john.c View Post
    You need a different book if it's asking you questions without teaching you what you need to know to answer them.
    It's a course I'm taking at the university.
    There are some lectures and presentations but it doesn't provide us with all the syntactical manipulations...

  4. #4
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    302
    You should be buying a good, reliable and beginner friendly C/C++ book as john mentions. If that's an issue, these are two older versions that you can refer to as of now. I think there's enough info in there to be able to answer these questions. I've learnt a tonne from C++: The Complete Reference along with trial and error but I didn't initially start programming reading it. It was "Computer Science with C++" by Sumita Arora. Lacks a lot of content, but it's perfect as per the education system guidelines in my country.

    https://doc.lagout.org/programmation...mer%20Plus.pdf
    http://160592857366.free.fr/joe/eboo...rence%204e.pdf

    You do need to practice quite a bit to understand better as simple programs presented in books are useless and sometimes not the best/efficient way of doing certain things. They'll, however, fill in the gaps in your knowledge. Good luck!

  5. #5
    Registered User
    Join Date
    Nov 2019
    Posts
    135
    Quote Originally Posted by Zeus_ View Post
    You should be buying a good, reliable and beginner friendly C/C++ book as john mentions. If that's an issue, these are two older versions that you can refer to as of now. I think there's enough info in there to be able to answer these questions. I've learnt a tonne from C++: The Complete Reference along with trial and error but I didn't initially start programming reading it. It was "Computer Science with C++" by Sumita Arora. Lacks a lot of content, but it's perfect as per the education system guidelines in my country.

    https://doc.lagout.org/programmation...mer%20Plus.pdf
    http://160592857366.free.fr/joe/eboo...rence%204e.pdf

    You do need to practice quite a bit to understand better as simple programs presented in books are useless and sometimes not the best/efficient way of doing certain things. They'll, however, fill in the gaps in your knowledge. Good luck!
    Thank you all.

  6. #6
    Registered User
    Join Date
    Dec 2017
    Posts
    952
    It's a technical point, but "object" pointers and "function" pointers are not necessarily compatible. So converting a function pointer to void* and back again may not yield the original pointer. It is however legal to convert a function pointer to a function pointer of a different type.

    And here's a site that converts C declaration gibberish to English. cdecl: C gibberish ↔ English
    Last edited by john.c; 11-30-2019 at 03:59 PM.
    If you want the truth to stand clear before you, never be for or against. - Sent-ts'an

  7. #7
    Registered User
    Join Date
    Nov 2019
    Posts
    135
    Quote Originally Posted by john.c View Post
    It's a technical point, but "object" pointers and "function" pointers are not necessarily compatible. So converting a function pointer to void* and back again may not yield the original pointer. It is however legal to convert a function pointer to a function pointer of a different type.

    And here's a site that converts C declaration gibberish to English. cdecl: C gibberish ↔ English
    Thanks for the info. and reference!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question 1-9 The c programming language K&R
    By danielj1988 in forum C Programming
    Replies: 3
    Last Post: 08-03-2016, 07:39 AM
  2. I have a question about the c language
    By artistunknown in forum C Programming
    Replies: 5
    Last Post: 02-15-2010, 05:46 PM
  3. Replies: 8
    Last Post: 07-30-2008, 05:37 AM
  4. Assembly Language Question
    By John_L in forum Tech Board
    Replies: 2
    Last Post: 03-13-2008, 07:44 PM
  5. language design question
    By elad in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2004, 10:14 AM

Tags for this Thread