Variable Pointer in C

//////////Variable Pointer/////////////
Output value at the address
#include <stdio.h>
int main(void)
{
  int number = 0;                
  int *pointer = NULL;           
  number = 10;
  pointer = &number;           

  printf("\npointer's value: %p", pointer);  /* Output the value (an address) */
  printf("\nvalue pointed to: %d\n", *pointer);       /* Value at the address */
  return 0;
}
/////////Put values in the memory locations by using pointers////////
#include <stdio.h>
main(){
    int a[5];
    int *b;
    int *c;
    int i;
    for(i = 0;i<5;i++){
        a[i]=i;
    }
    for(i = 0;i<5;i++)   {
        printf("value in array %d\n",a[i]);
    }

    b=a;
    b++;
    *b=4;
    b++;
    *b=6;
    b++;
    *b=8;
    b++;
    *b=10;
    b++;
    *b=12;

    printf("after\n\n\n");
    for(i = 0;i<5;i++)   {
        printf("value in array %d\n",a[i]);
    }
}
///////////COMMENTS////////////
Adding Comments
Comments in a C program have a starting point and an ending point.
Everything between those two points is ignored by the compiler.
/* This is how a comment looks in the C language */
The beginning of the comment is marked by the slash and the asterisk: /*.
The end of the comment is marked by the asterisk and the slash: */.
#include <stdio.h>

int main(){
   /* This is the comment.*/
   printf("%15s","right\n");
   printf("%-15s","left\n");
   return(0);
}
////////Using Comments to Disable///////
#include <stdio.h>
int main(){
 
   /* printf("%15s","right\n"); */
   printf("%-15s","left\n");
   return(0);
}
The comments are enclosed in '/*...*/'
#include <stdio.h>
main(){
  printf("Hi Amber \n");  /* This is the comments.*/
}
////Source code header comments/////////
  1. At the beginning of the program is a comment block.
  2. The comment block contains information about the program.
  3. Boxing the comments makes them stand out.
The some of the sections as follows should be included.
  1. Heading.
  2. Author.
  3. Purpose.
  4. Usage.
  5. References.
  6. File formats. A short description of the formats which will be used in the program.
  7. Restrictions.
  8. Revision history.
  9. Error handling.
  10. Notes. Include special comments or other information that has not already been covered.
/********************************************************          
    * hello -- program to print out "Hello World".         *  
    *                                                      *  
    * Author:  FirstName, LastName                         *  
    *                                                      *  
    * Purpose:  Demonstration of a simple program.         *  
    *                                                      *  
    * Usage:                                               *  
    *      Runs the program and the message appears.       *  
    ********************************************************/
  

    #include <stdio.h>
    int main()
    { 

        /* Tell the world hello */
        printf("Hello World\n");  
        return (0);
    }
/////CONVENTION/////
Indentation and Code Format
while (! done) {   

        printf("Processing\n");    

        next_entry();  

    }  

    if (total <= 0) {  

        printf("You owe nothing\n");   

        total = 0

    else {   

        printf("You owe %d dollars\n", total)

        all_totals = all_totals + total;   

    }
In this case, curly braces ({}) are put on the same line as the statements.
The other style puts the {} on lines by themselves:
while (! done)     
    {  
        printf("Processing\n");    

        next_entry();  
    }  

    if (total <= 0)    
    {  

       printf("You owe nothing\n");    

       total = 0;  

    }  
    else   
    {  

       printf("You owe %d dollars\n", total);  

       all_totals = all_totals + total;    

    }
////Header Files////
#include <stdio.h>

int main(void)
{
  printf("\nBe careful!!\a");
  return 0;
}
////////Common Headers //////////
HeaderPurpose
assert.hDefines the assert() macro
ctype.hCharacter handling
errno.hError reporting
float.hDefines implementation-dependent floating-point limits
limits.hdependent limits
locale.hLocalization
math.hmath library
setjmp.hNonlocal jumps
signal.hSignal handling
stdarg.hVariable argument lists
stddef.hConstants
stdio.hI/O system
stdlib.hMiscellaneous declarations
string.hstring functions
time.hsystem time functions
//////Headers Added by C99///////////
HeaderPurpose
complex.hcomplex arithmetic.
fenv.hGives access to the floating-point status flags and other aspects of the floating-point environment.
inttypes.hDefines a standard, portable set of integer type names. Also supports functions that handle greatest-width integers.
iso646.hAdded in 1995 by Amendment 1. Defines macros that correspond to various operators, such as && and ^.
stdbool.hSupports Boolean data types. Defines the macro bool, which helps with C++ compatibility.
stdint.hDefines a standard, portable set of integer type names. This file is included by .
tgmath.hDefines type-generic floating-point macros.
wchar.hmultibyte and wide-character functions.
wctype.hmultibyte and wide-character classification functions
////////External references//////////
 Extern definition is used when referencing a function or variable defined outside.
// Program in file externa1.c
#include <stdio.h>               
#include <c:\f1.cpp>
extern int i;                    
main()
{
    i =0;                        
    printf("value of i %d\n",i);
}
// Program in file f1.cpp
int i =7;
 
//////////////GCC/////////////
Compile and link the test.c source code:
gcc filename.c -o filename
#include <stdio.h>
 
int main()
{
    printf("Goodbye!\n");
    return(0);
}

Comments

Popular posts from this blog

Error : DependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.adobe.aem:uber-jar:jar:apis -> version 6.3.0 vs 6.4.0

Operators in Asterisk with Linux

ERROR Exception while handling event Sitecore.Eventing.Remote.PublishEndRemoteEventException: System.AggregateExceptionMessage: One or more exceptions occurred while processing the subscribers to the 'publish:end:remote'