Some Basics Ideas About c Program

Embed Size (px)

Citation preview

  • 8/6/2019 Some Basics Ideas About c Program

    1/6

    SOME BASICS IDEAS ABOUT C PROGRAM::

    1.How can you write a c prog without header files?

    A:

    c programming run without header filewrite example given below.

    void main(){

    clrscr();printf("hello");

    getch();}

    2.

    What is object file? How can you access object file?

    A:

    When a c program is compiled the source code is converted into object file i.e., a.out this file is known asobject file.

    An object file is binary representation of source(text) file. On Linux, object and executable files have ELFformat. It's a collection of various sections segragating type of data in:

    - text section- data section

    - stack- heap

    Also addresses in an object file are relative and hence object files can't be run unless it's linked. for ex, if you

    make a call to printf(), object file will have an entry as("call printf ___") where the blank is the address of printf function. Since printf is part of libc.so, you have no

    knowledge of its address. Linking with libc pads the correct address and enable you to call it successfully.

    3.

    How to print value without using any output statements?

    A:

    We can also print the output of a program in another way.First you save the program with filename.h

    later use this filename in another program using this statement.#include"filename.h"

  • 8/6/2019 Some Basics Ideas About c Program

    2/6

    so that now we can print the output of tat program..

    4.

    Define structural language and procedural language?

    A:

    Structural language is one which can have a specific structure.c is a structured language

    before structural language procedural language was used.

    Structural language is one which can have a specific structure.

    c is a structured languagebefore structural language procedural language was used.

    5.

    Can you define which header file to include at compile time?

    A:

    Yes. This can be done by using the #if, #else, and #endif preprocessor directives. For example, certain

    compilers use different names for header files. One such case is between Borland C++, which uses the headerfile alloc.h, and Microsoft C++, which uses the header file malloc.h. Both of these headers serve the same

    purpose, and each contains roughly the same definitions. If, however, you are writing a program that is tosupport Borland C++ and Microsoft C++, you must define which header to include at compile time. The

    following example shows how this can be done:

    #ifdef _ _BORLANDC_ _

    #include #else

    #include #endif

    6.

    What is :- Asembler , compiler , Preprocessor , laxical analysis , parsing

    A:

    ASSEMBLER is a computer program which converts the assembly language program into machine level

    language.COMPILER is a progam or set of programs which converts the high level language into machine level

    language.

  • 8/6/2019 Some Basics Ideas About c Program

    3/6

    PREPROCESSOR is a computer program that processes input to produce an output which again serves as a

    input to another program.LEXICAL ANALYSIS is the process of converting a sequence of characters into a sequence of tokens.

    PARSING is the process of analyzing a sequence of tokens to determine their grammatical structure.it is

    also called as syntactic analysis.

    7.

    What is #line used for?

    A:

    The #line preprocessor directive is used to reset the values of the _ _LINE_ _ and _ _FILE_ _ symbols,

    respectively. This directive is commonly used in fourth-generation languages that generate C languagesource

    files.

    The #hash character starts the line to denote a preprocessor instruction and it must be placed at start ofthe page,before the actual program code is processed

    8.

    What are the different storage classes in C ?

    A:

    C has three types of storage: automatic, static and allocated.

    Variable having block scope and without static specifier have automatic storage duration.

    Variables with block scope, and with static specifier have static scope. Global variables (i.e, file scope) withor without the the static specifier also have static scope.

    Memory obtained from calls to malloc(), alloc() or realloc() belongs to allocated storage class.

    C contains 4 types of storage classes:

    1.Automatic:auto-Local variable which is known only to the function in which it is declared.

    2.Extern:

    Global variable which known to all functions in the file.3.Static:

    Local or global variable which exists & retain its value even after control is transferred to calling function.4.Register:

    Local variable which is stored in register instead

    9.

  • 8/6/2019 Some Basics Ideas About c Program

    4/6

    What is an abstract class?

    A:

    A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be

    inherited and have the methods over-ridden. Essentially, it is a blueprint for a class without any

    implementation.

    An Abstract class is class that is not used to create objects and is only meant to act as base class whose

    members can be inherited by derived class.

    10.

    How can you improve your c knowledge........

    A:

    C is the fundamental language.It is the language of languages.To improve the skill regarding C u can

    follow the points:-

    1.consistent reading

    2.understanding the program properly and working upon same type of program.

    3.try to write programs of ur own.

    go and study denis richie.you can also follow bruce eckel.

    do keep visiting this page regularly we will be updating it for u.

    Fundamentals of C language:

    C (pronounced /si/see) is a general-purpose computerprogramming language developed between 1969 and 1973 by Dennis

    Ritchie at the Bell Telephone Laboratories for use with the Unixoperating system.[2]

    Although C was designed for implementing system software,[5]

    it is also widely used for developing portable application software.

    C is one of the most popular programming languages of all time[6][7]

    and there are very few computer architectures for which a

    C compilerdoes not exist. C has greatly influenced many other popular programming languages, most notably C++, which began as

    an extension to C.

  • 8/6/2019 Some Basics Ideas About c Program

    5/6

    Like most imperative languages in theALGOL tradition, C has facilities forstructured programming and allows lexical variable

    scope and recursion, while a static type system prevents many unintended operations. In C, all executable code is contained

    within functions. Function parameters are always passed by value. Pass-by-reference is simulated in C by explicitly

    passing pointervalues. Heterogeneous aggregate data types (struct) allow related data elements to be combined and manipulated as

    a unit. C program source text is free-format, using the semicolon as astatement terminator.

    C also exhibits the following more specific characteristics:

    Variables may be hidden in nested blocks

    Partially weak typing; for instance, characters can be used as integers

    Low-level access to computer memory by converting machine addresses to typed pointers

    Function and data pointers supporting ad hocrun-time polymorphism

    array indexing as a secondary notion, defined in terms of pointer arithmetic

    A preprocessorformacro definition, source code file inclusion, and conditional compilation

    Complex functionality such as I/O, string manipulation, and mathematical functions consistently delegated to library routines

    A relatively small set of reserved keywords

    A large number of compound operators, such as +=, -=, *=, ++, etc.

    C's lexical structure resembles B more thanALGOL. For example:

    Compound statement blocks are delimited with { ... } rather than begin ... end

    = is used for assignment (copying), like Fortran, rather than ALGOL's :=

    == is used to test for equality (rather than .EQ. in Fortran, or= in BASIC and ALGOL)

    Logical "and" and "or" operators are represented with && and ||, which don't evaluate the right operand if the result can be

    determined from the left alone (short-circuit evaluation), and are semantically distinct from the bit-wise operators & and |

    The initial development of C occurred atAT&TBell Labs between 1969 and 1973;[3]

    according to Ritchie, the most creative period

    occurred in 1972. It was named "C" because its features were derived from an earlier language called "B", which according to Ken

    Thompson was a stripped-down version of the BCPL programming language.

    The origin of C is closely tied to the development of the Unix operating system, originally implemented in assembly language on

    a PDP-7 by Ritchie and Thompson, incorporating several ideas from colleagues. Eventually they decided to port the operating

    system to a PDP-11. B's inability to take advantage of some of the PDP-11's features, notably byte addressability, led to the

    development of an early version of C.

    The original PDP-11 version of the Unix system was developed in assembly language. By 1973, with the addition ofstruct types,

    the C language had become powerful enough that most of the Unixkernel was rewritten in C. This was one of the first operating

  • 8/6/2019 Some Basics Ideas About c Program

    6/6

    system kernels implemented in a language other than assembly. (Earlier instances include the Multics system (written in PL/I), and

    MCP (Master Control Program) for the Burroughs B5000 written inALGOL in 1961.)